Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameResolutionFailure in Mono but not .NET

Tags:

c#

.net

mono

I am making HTTPS POST requests (same problem with HTTP) using C#

byte[] byteArray = Encoding.UTF8.GetBytes("var1=blah&var2=hah");
HttpWebRequest request = (HttpWebRequest)(WebRequest.Create("https://www.example.com"));
request.Credentials = CredentialCache.DefaultCredentials;
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
request.Method = "POST";
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();

The preceding code works great in both .NET and Mono when I don't have to go through a proxy. When I have to use a proxy, then it works when run on .NET but in Mono fails with the following

WebException: Error: NameResolutionFailure
    at System.Net.HttpWebRequest.EndGetRequestStream (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
    at System.Net.HttpWebRequest.GetRequestStream () [0x00000] in <filename unknown>:0

Also, running in a browser with the same proxy configuration works fine. Any reason why Mono would throw a NameResolutionFailure while .NET does not?

There was a similar stackoverflow question that had a work around of using the direct ip when creating the request and then adding the domain to the request.Host. However, the proxy I have to go through rejects this kind of request. Help!

Operating System is Windows 7, Mono version is 2.6.5

like image 466
SlyMcFly Avatar asked Oct 16 '12 19:10

SlyMcFly


1 Answers

Hint: First of all check your web browse in your phone. If it will be the same situation - then you have to worry about. I had the same situation and it happened all time when EMULATOR doesn't have permission to net. Try on normal device.

like image 79
Marek Woźniak Avatar answered Oct 06 '22 00:10

Marek Woźniak