473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HTTPWebRequest unescapes automatically

I am trying to use HTTPWebRequest to make a server side HTTP request to get response XML from a vendor. The vendor expects a bunch of querystring parameters, some of which have special characters in their values.

For some reason HTTPWebRequest automatically unescapes these values in the querystring of the URL and messes up the end result. I then tried to use the System.URI.URI object and used the dontEscape=true constructor. But then later realized that this constructor has become obsolete since .NET 2.0.

Does anyone have any solution for this? Is there an alternative to calling HTTPWebRequest to make a server side HTTP GET request?

Thanks in advance.
Jun 21 '07 #1
7 5681
Plater
7,872 Expert 4TB
URL's should always be sent escaped (ie: a %20 instead of a space), I'm fairly sure it's part of the RFC for the protocol.
However, there are Escape() and Unescape() functions you might be able to use to your advantage. As well being able to piece all of the query string parameters back together if need be.
Jun 21 '07 #2
The querystring is correctly escaped/unescaped. If I try to escape it again and send, the HTTPWebRequest call does not unescape it at all. For some reason it is acting wierd. Below is the value that I need to pass in the querystring.

Expand|Select|Wrap|Line Numbers
  1. zxeti%8Mfjus%2Nfxgdvetsa%7F057.0.1.4%5Cekefqrab%9Mhfl%1Fx-sytz-dvet-sfkgnus%7NVcha-Aioyu%546A%2MNycrolc%362I3.0%2M%2811cqwabdlkoe%264L%1EMUSP%2E5.0%264L%1EWkxopgv%5BPD%3L8.4%454C%5KVV3%363E%5B.XPU%5KFLT%3C1.0.4523%2812%4Mcfcxuwsdi%8Munoexkydo%1Fvgbdjyq%0C7.6%2Fbhsuszo%0Lgi43%4K4012561056962-%3Dfhaviqx%8M8.8%4Mlddlxqif%8DPHL9C157052M77E1L2P9K663744PI670%2Nrs%6F43%3Dan%0C40%3MA-Lnuz-Vcha-Hgkofbv%0CWcps-Dphnv%4B+Pxcinvl%2I3.0+(npwsjwidvp%3E+PSKO+7.3%6B+Gtonrfv+PD+6.4%6B+CG2%6K+.POE+MOA+1.1.5351)::32B960B0DEC4AFE72915AE7AA584BA62
Jun 21 '07 #3
Plater
7,872 Expert 4TB
Now I am confused at what the problem is?

Take that string as exactly as you want it to appear, and put it into the httpWebRequest object. The object will escape it, send it, and the server will unescape it back to its original form.
I don't think you have to manually escape/unescape it.

Other then that I am lost at what the problem actually is.


If all else fails, bust out a Socket and send it yourself.
Jun 21 '07 #4
Well sorry to confuse you. Let me try to explain again.

In the server side code of my application I make a HTTPWebRequest to a 3rd party vendor which uses HTTP Get to serve an XML formatted result. One of the parameters in this querystring is a long encoded string. If I open up a browser window and paste in this encoded string along with the URL, it works fine and returns the expected XML. But if I try to make the same call through HTTPWebRequest the result is an error. Hence the only reason it doesnt work is that the encoded string is messed up along the way (confirmed by intercepting the call through Fiddler). The encoded string is unescaped by the call.

I tried to HttpUtility.UrlEncode before passing it to WebRequest.Create method, but the same error. Then I tried UrlDecode and that didnt work either.

Does that make sense now?
Jun 21 '07 #5
TRScheel
638 Expert 512MB
The querystring is correctly escaped/unescaped. If I try to escape it again and send, the HTTPWebRequest call does not unescape it at all. For some reason it is acting wierd. Below is the value that I need to pass in the querystring.

Expand|Select|Wrap|Line Numbers
  1. zxeti%8Mfjus%2Nfxgdvetsa%7F057.0.1.4%5Cekefqrab%9Mhfl%1Fx-sytz-dvet-sfkgnus%7NVcha-Aioyu%546A%2MNycrolc%362I3.0%2M%2811cqwabdlkoe%264L%1EMUSP%2E5.0%264L%1EWkxopgv%5BPD%3L8.4%454C%5KVV3%363E%5B.XPU%5KFLT%3C1.0.4523%2812%4Mcfcxuwsdi%8Munoexkydo%1Fvgbdjyq%0C7.6%2Fbhsuszo%0Lgi43%4K4012561056962-%3Dfhaviqx%8M8.8%4Mlddlxqif%8DPHL9C157052M77E1L2P9K663744PI670%2Nrs%6F43%3Dan%0C40%3MA-Lnuz-Vcha-Hgkofbv%0CWcps-Dphnv%4B+Pxcinvl%2I3.0+(npwsjwidvp%3E+PSKO+7.3%6B+Gtonrfv+PD+6.4%6B+CG2%6K+.POE+MOA+1.1.5351)::32B960B0DEC4AFE72915AE7AA584BA62

Curiously, is there a maxium size? I always thought there was, and I would be sure this breaks that maximum size if there was ( I could swear its 255 characters...).

Just a thought, and I am not sure of it to begin with.
Jun 21 '07 #6
Plater
7,872 Expert 4TB
Curiously, is there a maxium size? I always thought there was, and I would be sure this breaks that maximum size if there was ( I could swear its 255 characters...).

Just a thought, and I am not sure of it to begin with.
The RFC for HTTP has a specific max line length I believe. (But it might just be SMTP that has that)

But regardless if it gets pasted into the URL bar just fine, it should work in the request object.

If there's not a security issue, would we be able to get the code/address for doing this (maybe send either me or TR a PM if that's better) so we can fiddle with it?
I admit, this has me curious.

That same text you posted, as URLEncoded
[notag]
zxeti%8Mfjus%2Nfxgdvetsa%7F057.0.1.4%5Cekefqrab%9M %20%20hfl%1Fx-sytz-dvet-sfkgnus%7NVcha-Aioyu%546A%2MNycrolc%362I3.0%2M%2811cqwabdlkoe%264 %20%20L%1EMUSP%2E5.0%264L%1EWkxopgv%5BPD%3L8.4%454 C%5KVV%20%203%363E%5B.XPU%5KFLT%3C1.0.4523%2812%4M cfcxuwsdi%8M%20%20unoexkydo%1Fvgbdjyq%0C7.6%2Fbhsu szo%0Lgi43%4K40125%20%2061056962-%3Dfhaviqx%8M8.8%4Mlddlxqif%8DPHL9C157052M77E1L2P9 %20%20K663744PI670%2Nrs%6F43%3Dan%0C40%3MA-Lnuz-Vcha-Hgkofbv%0CWcps-Dphnv%4B+Pxcinvl%2I3.0+(npwsjwidvp%3E+PSKO+7.3%6B+ %20%20Gtonrfv+PD+6.4%6B+CG2%6K+.POE+MOA+1.1.5351): :32B96%20%200B0DEC4AFE72915AE7AA584BA62
[/notag]
Jun 21 '07 #7
Am sorry you wont be able to execute it on your end. The vendor has IP security for the HTTP Get call.

Here is the HTTPWebRequest code if that helps.

Expand|Select|Wrap|Line Numbers
  1.         string infospaceUrl = "http://www.something.com/page=thelongstring";
  2.         try
  3.         {
  4.             UTF8Encoding encoding = new UTF8Encoding();
  5.             byte[] encodedPayload = encoding.GetBytes("");
  6.  
  7.             // Set up our connection
  8.             Uri uri = new Uri(HttpUtility.UrlPathEncode(infospaceUrl));
  9.             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
  10.             request.Method = WebRequestMethods.Http.Get;
  11.             request.ContentType = "text/xml";
  12.             request.ContentLength = encodedPayload.Length;
  13.  
  14.             // Get the Response
  15.             using (StreamReader responseStream = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.UTF8))
  16.             {
  17.                 context.Response.Write(responseStream.ReadToEnd());
  18.             }
  19.         }
  20.         catch (Exception httpexception)
  21.         {
  22.             throw new HttpException(httpexception.Message + " " + infospaceUrl);
  23.         }
Jun 21 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Cliff Harris | last post by:
I am trying to automate a series of form posts on a website. This site requires that my session be kept alive through successive posts (it basically tracks me by a sessionid, and if I get a new...
1
by: Jeff B | last post by:
I'm trying to create a simple screen scraping application and I kept getting a System.Net.WebException thrown back with a message of "The operation has timed-out." At first I thought it was some...
1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
3
by: Amil | last post by:
Please don't repond to this if you are guessing or just don't know the answer. I'm trying to login to a backend system running Java/Tomcat. I create a HttpWebRequest with the login data and do...
4
by: Andy Fish | last post by:
Hi, I have a web app that I want to make calls back into itself (preserving the session cookies etc). I am using a System.Net.HttpWebRequest object to make the request, but I am having...
6
by: Mike Koerner | last post by:
Hi, I am having problems setting the HttpWebRequest Date header. I understand that it is a restricted header and I do receive the "This header must be modified with the appropriate property." ...
0
by: Nick | last post by:
Is there a way to avoid using a specific TCP port number, on the client side, when using HttpWebRequest? I've written an HTTP server and client that can't communicate with each other when the...
8
by: shankararaman.s | last post by:
Hi, I am trying to develop an interface which will fetch all my Yahoo mails. I am not able to sign in to yahoo by posting the form with my username & password. Please find my code below and...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
I am using HTTPWebRequest to programatically send a HTTP POST request. I have a long string (400 characters): dim str as string = "xxxxx...." It is a value that is passed in the HTTP Post...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.