This is not the first time I'm using this method to send a POST request, and I never had any problems:
public static Stream SendPostRequest(Uri uri, byte[] postData)
{
var request = WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postData, 0, postData.Length);
requestStream.Close();
return request.GetResponse().GetResponseStream();
}
On request.GetRequestStream() I'm getting a System.Net.WebException: The underlying connection was closed: An unexpected error occured on a send.
Even more interesting, it works perfectly well on some machines, but doesn't work on my machine (Windows 7 Beta) and production server (Windows Server 2008). More information:
Works - Windows Xp - .NET 2.0
Works - Windows Xp - .NET 3.5
Works - Windows Server 2003 - .NET 3.0
Doesn't work - Windows Vista - .NET 3.5
Doesn't work - Windows Server 2008 - .NET 3.5
Doesn't work - Windows 7 Beta - .NET 3.5 SP1
Tried:
- Bunch of stuff from here, nothing helped.
- Using WebClient, nothing changed.
- Tweaking these options, but didn't notice any notable difference.
- Tried WireShark. A very good tool.
[Solved. Kinda]
I forgot to mention, but Uri was https... I tried http and it worked. Can't believe, I didn't try that sooner...
Still, I would appreciate, if someone would shine a light on this whole situation.