Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpWebRequest - The underlying connection was closed: An unexpected error occurred on a send

I'm attempting to post JSON data to a web API and get the resulting json object back. I'm using HttpWebRequest to post to an https address using basic authentication. On the request.GetResponse() I'm getting an error of

The underlying connection was closed: An unexpected error occurred on a send.

and an inner exception of

Received an unexpected EOF or 0 bytes from the transport stream.

My test application is compiled against .NET 4.0 The application works on machines running 4.5, however fails to run on several machines running 4.0. Upgrading to 4.5 on those machines is not a simple task. While pouring through the trace log, I've noticed only 1 difference before the failure occurs which I've included below. Any help would be appreciated.

System.Net Information: 0 : [5876] ConnectStream#9956401 - Sending headers
{
Content-Type: application/json
Authorization: Basic <encoded base64 auth string is here>
Host: <host name is here>
Content-Length: 130
Expect: 100-continue
Connection: Keep-Alive
}.

While trying to research this error, I came across two recurring issues, neither of which seem to apply to my error, but I tried the fixes anyway. I've tried forcing SSL3 (though authentication isn't the issue) and also turning off Keep-Alive. Neither work.

like image 841
Ken Avatar asked Jun 11 '14 20:06

Ken


1 Answers

I had a similar problem. I was trying to download a file via .net WebClient class.

It turned out that Apache server had wrong name in VirtualHost::ServerName.

like image 146
andrew.fox Avatar answered Sep 20 '22 11:09

andrew.fox