C# .Net 2.0 ResponseUri.Query empty – Education Career Blog

I have a problem when I do an httprequest and the remote server responds with a redirect and some additional query parameters. The problem is that the additional parameters is empty on certain enviroments.

When I run the code in a test-environment the parameters is not empty.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
 WebProxy myProxy = new WebProxy();
 Uri newUri = new Uri(ConfigurationManager.AppSettings"proxyUrl");
 myProxy.Address = newUri;
 request.Proxy = myProxy;
 request.Timeout = Int32.Parse(ConfigurationManager.AppSettings"PBVtimeout");
 request.AllowAutoRedirect = true;
 request.MaximumAutomaticRedirections = 2;

 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(myCertificateValidation);

 HttpWebResponse response = (HttpWebResponse)request.GetResponse();

 log.Debug("PathAndQuery: " + response.ResponseUri.PathAndQuery);
 log.Debug("Statuscode: " + response.StatusCode);
 log.Debug("Statusdescription: " + response.StatusDescription);

 Uri uri = response.ResponseUri;
 NameValueCollection qscol = ParseQueryString(uri.Query);

 return qscol"Status" + qscol"Status_code";

I log StatusCode, StatusDescription and the PathAndQuery of the response. StatusCode and StatusDescription is “OK” in both enviroments but the PathAndQuery looks like this:

Faulty environment: localhost/Service

Correct environment: localhost/Service?Merchant_id=1345&Version=2&Customer_refno=269932&Status=E&Status_code=48

As you can see the faulty enviroments is missing the parameters.

My initial thought was that it was a problem with a firewall “cleaning” the redirect response. But when I did the http request in an ordninary web browser it worked fine.

The code is in C# .Net 2.0 and it runs on a Windows 2003 server.

Any ideas where the problem could be?

Leave a Comment