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

T

Tom

Dear all,
when I ran the following code, I always got "The underlying connection was closed: An unexpected error occurred on a send" error, it happend at "httpReq.GetResponse();" and the stack trace is
************start of stack trace***************************
The underlying connection was closed: An unexpected error occurred on a send. at System.Net.HttpWebRequest.CheckFinalS
tatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
***********end of stack trace**************88
Much appreciated for any help!
Tom
****************************************************
try
{
HttpWebRequest httpReq = (HttpWebRequest) WebRequest.Create("https://test/kkk");
httpReq.ContentType = "text/xml";
httpReq.Method = "POST";
httpReq.KeepAlive=false;
byte[] requestbody = Encoding.UTF8.GetBytes("<test>kkk</test>");
Stream requestStream = httpReq.GetRequestStream();
int length = requestbody.Length;
requestStream.Write(requestbody,0,length);
requestStream.Close();
X509Certificate x509 = X509Certificate.CreateFromCertFile("C:\\kk\\509cer.cer");
ttpReq.ClientCertificates.Add(x509);
HttpWebResponse webResponse = (HttpWebResponse) httpReq.GetResponse();
}
catch (WebException ex)
{
Response.Write(ex.Message);
}
catch (Exception err)
{
Response.Write(err.Message);
}
 
J

Joe Kaplan \(MVP - ADSI\)

It is very likely an SSL problem. Do you seen any SChannel errors in the
event log? Do you get any certificate warnings when you do the same action
in the browser?

Oftentimes these errors can be overcome by creating a custom
ICertificatePolicy object that ignores the error you are getting, but it is
always better to solve the actual problem instead.

Joe K.

Tom said:
Dear all,
when I ran the following code, I always got "The underlying connection
was closed: An unexpected error occurred on a send" error, it happend at
"httpReq.GetResponse();" and the stack trace is
************start of stack trace***************************
The underlying connection was closed: An unexpected error occurred on a
send. at System.Net.HttpWebRequest.CheckFinalS
tatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
***********end of stack trace**************88
Much appreciated for any help!
Tom
****************************************************
try
{
HttpWebRequest httpReq = (HttpWebRequest) WebRequest.Create("https://test/kkk");
httpReq.ContentType = "text/xml";
httpReq.Method = "POST";
httpReq.KeepAlive=false;
byte[] requestbody = Encoding.UTF8.GetBytes("<test>kkk</test>");
Stream requestStream = httpReq.GetRequestStream();
int length = requestbody.Length;
requestStream.Write(requestbody,0,length);
requestStream.Close();
X509Certificate x509 = X509Certificate.CreateFromCertFile("C:\\kk\\509cer.cer");
ttpReq.ClientCertificates.Add(x509);
HttpWebResponse webResponse = (HttpWebResponse) httpReq.GetResponse();
}
catch (WebException ex)
{
Response.Write(ex.Message);
}
catch (Exception err)
{
Response.Write(err.Message);
}
 
T

Tom

Thanks Joe, After analysing the problem, I found the the connection failed at the handshake phase, I modified the SSLwebclient SDK sample (security SSPI sample) and reproduce the problems. More specifically, it failed at InitializeSecurityContext with the error message "An unknown error happened when processing the certificate"
Now I am checking whether all the certificates were installed correctly

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top