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

Discussion in 'ASP .Net Security' started by Tom, May 11, 2004.

  1. Tom

    Tom Guest

    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);
    }
     
    Tom, May 11, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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);
    > }
     
    Joe Kaplan \(MVP - ADSI\), May 11, 2004
    #2
    1. Advertising

  3. Tom

    Tom Guest

    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
     
    Tom, May 13, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TCook
    Replies:
    0
    Views:
    6,422
    TCook
    Mar 4, 2006
  2. imonline
    Replies:
    0
    Views:
    941
    imonline
    Jan 22, 2008
  3. Emre Aydinceren
    Replies:
    4
    Views:
    199
    Emre Aydinceren
    Aug 7, 2003
  4. Robert Walter
    Replies:
    1
    Views:
    200
    Robert Walter
    Aug 19, 2003
  5. Franck
    Replies:
    0
    Views:
    217
    Franck
    Nov 12, 2003
Loading...

Share This Page