Visual Basic Development Bookmark and Share   
 Home > Visual Basic Interop and Upgrade > Error while executing httpwebrequest.getrequeststream.
 

Error while executing httpwebrequest.getrequeststream.

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.
  •  
AnilM_Nair  Wednesday, November 04, 2009 10:46 AM
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.
Riquel_Dong  Tuesday, November 10, 2009 9:59 AM
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.
Riquel_Dong  Tuesday, November 10, 2009 9:59 AM

You can use google to search for other answers

Custom Search

More Threads

• GetType on a COM object
• SQL Binary data (image type) into MS Word
• What is the solution for this problem?
• Passing an array byref from VBA to VB.net
• Upgrade failed: Application has caused an exception
• Help using Interop Forms.
• VB 2005 Blues
• Creating Data Base with XAMPP
• Import Excel 2007 to Sql Server Using VB.Net
• Unable to cast COM object of type 'System.__ComObject' to class type 'rjsDocMan.Folder'.