HttpWebRequest and QueryString

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Gallucci

    #1

    HttpWebRequest and QueryString

    I'm trying to execute a "POST" with a HttpWebRequest object that has a Uri containing a QueryString. The QueryString is being
    Url-Encoded by the object. The server receiving the "POST" is not Url-Decoding the QueryString and I have no control over
    this behavior.

    Can someone show me how to prevent the Url-Encoding of the HttpWebRequest. RequestUri?

    Thanks,

    ChrisG


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: HttpWebRequest and QueryString

    Chris,

    By default, I believe the Uri class escapes the characters in the query
    string. In order to get around this, create an instance of the Uri
    yourself, and use the constructor with a boolean parameter. Pass true for
    this and it will not escape the query string.

    Then, pass this Uri instance to the static Create method on the
    WebRequest class.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Chris Gallucci" <chris@gallucci .com> wrote in message
    news:_Dvsb.1833 97$Fm2.165797@a ttbi_s04...[color=blue]
    > I'm trying to execute a "POST" with a HttpWebRequest object that has a Uri[/color]
    containing a QueryString. The QueryString is being[color=blue]
    > Url-Encoded by the object. The server receiving the "POST" is not[/color]
    Url-Decoding the QueryString and I have no control over[color=blue]
    > this behavior.
    >
    > Can someone show me how to prevent the Url-Encoding of the[/color]
    HttpWebRequest. RequestUri?[color=blue]
    >
    > Thanks,
    >
    > ChrisG
    >
    >[/color]


    Comment

    • Chris Gallucci

      #3
      Re: HttpWebRequest and QueryString

      Bingo!

      I wasn't equating "escaping" with "encoding".

      Thanks, Nicholas.

      (P.S. Sorry to the mods; I actually meant to post this in .clr)

      ChrisG
      [color=blue]
      > Chris,
      >
      > By default, I believe the Uri class escapes the characters in the query
      > string. In order to get around this, create an instance of the Uri
      > yourself, and use the constructor with a boolean parameter. Pass true for
      > this and it will not escape the query string.
      >
      > Then, pass this Uri instance to the static Create method on the
      > WebRequest class.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m[/color]


      Comment

      Working...