Visual Basic > Visual Basic Forums > Visual Basic Interop and Upgrade > Error while executing httpwebrequest.getrequeststream.
Ask a questionAsk a question
 

AnswerError while executing httpwebrequest.getrequeststream.

  • Wednesday, November 04, 2009 10:46 AMAnilM_Nair Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

      We migrated code from vb to vb.net. In vb msxml was used to make http requests and  in .net we changed to httpwebrequest. With this new implementation an exception is thrown while executing httpwebrequest.getrequeststream.

    The exception code is 10060 and the exception message is A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

     

    This exception occurs intermittently and not always.


    Please find below the code snippet which i've used to achieve the result

     

            Dim HttpRequest As HttpWebRequest

            Dim HttpResponse As HttpWebResponse

            Dim streamReader As StreamReader

            Dim streamWriter As StreamWriter

     

            HttpRequest = HttpWebRequest.Create(strUrl)

            HttpRequest.Method = WebRequestMethods.Http.Post

            HttpRequest.ContentType = "text/xml"

            HttpRequest.Timeout = 999999999

            HttpRequest.ContentLength = Str(Len(temp))

     

            streamWriter = New StreamWriter(HttpRequest.GetRequestStream)

            streamWriter.Write(temp)

            streamWriter.Flush()

            streamWriter.Close()

            HttpRequest.GetRequestStream.Close()

     

            HttpResponse = CType(HttpRequest.GetResponse, HttpWebResponse)

     

            streamReader = New StreamReader(HttpResponse.GetResponseStream)

            temp = streamReader.ReadToEnd

            streamReader.Close()

            HttpResponse.Close()

     

    Please advice on a resolution

    Thanks,
    Anil
    • Edited byAnilM_Nair Friday, November 06, 2009 1:04 AM.
    •  

Answers

  • Tuesday, November 10, 2009 9:59 AMRiquel_DongModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Anil,

    The error information means there are some network connection faults. In this situation you need to use try/catch block to handle the exception and set up connection again.
    Best regards,
    Riquel
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

All Replies

  • Tuesday, November 10, 2009 9:59 AMRiquel_DongModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Anil,

    The error information means there are some network connection faults. In this situation you need to use try/catch block to handle the exception and set up connection again.
    Best regards,
    Riquel
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.