0

I run queries on a server (Oracle Reports) from an ASP.NET application with the WebClient class. I don't have hand on the server, I just can access to some logs.

In one case, the query string sent to the server contains accented character (é). The WebClient class encode (UrlEncode) the query string before sending the request (é become %C3%A9). But my server don't understand this encoding !

After some tests with known clients (IE 11 and Chrome 32), I find that IE 11 does not encode the query string while Chrome yes.

On the server, I have the following logs for http://myserver/reports/rwservlet?test=é url :

IE : "GET / reports/rwservlet test=\XE9 HTTP/1.1 ?"

Chrome : "GET /reports/rwservlet test=%C3%A9 HTTP/1.1 ?"

With the WebClient class, I have the same result as whith Chrome.

What can I do to make my server receives the same URL as IE when I use it from the WebClient class ?

Can I say to WebClient class to not URLEncode my parameters values ? Or can I use other class than WebClient ?

Thank you !

In other words, I have to send an HTTP request from ASP.NET app with a query string not encoded ! I try with WebClient and with WebRequest, but URL is always encoded...

Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93
Olof
  • 524
  • 5
  • 20

1 Answers1

1

I cant make it work with POST method :

string url = "http://myUrl.com/page";
string parameters = "param1=un&param2=ooohyé"
byte[] bytes = Encoding.GetEncoding("ISO-8859-1").GetBytes(parameters);
WebRequest webRequest = WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = bytes.Length;

Stream paramStream = webRequest.GetRequestStream();
paramStream.Write(bytes, 0, bytes.Length);
paramStream.Close();

WebResponse response = webRequest.GetResponse();
Olof
  • 524
  • 5
  • 20