Converting HttpContext.Current.Request to HttpWebRequest

Last post 07-15-2004 1:30 PM by j_gaylord. 3 replies.

Sort Posts:

  • Converting HttpContext.Current.Request to HttpWebRequest

    07-13-2004, 9:01 AM
    • Contributor
      3,440 point Contributor
    • j_gaylord
    • Member since 11-25-2002, 8:14 AM
    • Exeter, PA
    • Posts 728
    • ASPInsiders
      TrustedFriends-MVPs
    How can I convert an HttpContext.Current.Request to HttpWebRequest?
    Jason N. Gaylord
    ASPInsider and Microsoft MVP
    http://jasongaylord.com
  • Re: Converting HttpContext.Current.Request to HttpWebRequest

    07-13-2004, 11:31 AM
    • Contributor
      3,440 point Contributor
    • j_gaylord
    • Member since 11-25-2002, 8:14 AM
    • Exeter, PA
    • Posts 728
    • ASPInsiders
      TrustedFriends-MVPs
    I keep getting the following error message:

    error BC30311: Value of type 'System.Web.HttpRequest' cannot be converted to 'System.Net.WebRequest'.

    objRequest = HttpContext.Current.Request '(CType(HttpContext.Current.Request, HttpWebRequest))
    Jason N. Gaylord
    ASPInsider and Microsoft MVP
    http://jasongaylord.com
  • Re: Converting HttpContext.Current.Request to HttpWebRequest

    07-14-2004, 11:12 PM
    • Contributor
      4,280 point Contributor
    • tomasr
    • Member since 04-28-2003, 11:18 AM
    • Colombia
    • Posts 852
    Jason,

    HttpContext.Current.Request is of type System.Web.HttpRequest, not of type System.Net.HttpWebRequest, so that can't be done.

    Why do you want to convert it to that?
    Tomas Restrepo [MVP]
    tomasr@mvps.org
  • Re: Converting HttpContext.Current.Request to HttpWebRequest

    07-15-2004, 1:30 PM
    • Contributor
      3,440 point Contributor
    • j_gaylord
    • Member since 11-25-2002, 8:14 AM
    • Exeter, PA
    • Posts 728
    • ASPInsiders
      TrustedFriends-MVPs
    Well, I found a way around what I needed to accomplish. I had a bad brain blockage this week. I was attempting to do this:
    Dim objRequest as HttpWebRequest
    
    Dim stmOutput as StreamReader

    objRequest = (CType(HttpContext.Current.Request, HttpWebRequest))
    stmOutput = New StreamReader(objRequest.GetRequestStream(),System.Text.Encoding.ASCII)
    I then realized I didn't have to do that. So, to get my Stream, I just grabbed the InputStream like this:
    Dim stmOutput as StreamReader
    

    stmOutput = New StreamReader(HttpContext.Current.Request.InputStream)
    Thanks to Ben for forcing me to think this through. ;)
    Jason N. Gaylord
    ASPInsider and Microsoft MVP
    http://jasongaylord.com
Page 1 of 1 (4 items)