• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

how to trap an timeout error on http posting/reply using vb6 code

I have a section of the code of VB6 that want to do http posting and get reply from an remote asp server application.  it works fine, but I need to figure out a way to trap the "timed-out" operations in case the remote server is not responding.

I use the on error goto err label trying to do this.  but it does not works.  The vb.exe program is running in a scheduler,  when the error occurs, (it does shows the timedout error) but not trapped in the code.  but it pops up a small debug window.   (but no one is attending the terminal,  so it hangs there....)

(If I set the on error code set before XMLRespone = xmlhttp.ResponseText
 will do the trick?)

Please look the sample code I attached here, and see what I did wrong. and any suggestion
you can help to "insert/modify" my code to do this purpose.


sub main()
 Dim xmlhttp As WinHttp.WinHttpRequest
 Dim strArg As String
 Dim strMSG As String
 Dim StrURL As String
 Dim XMLResponse As String
 Dim strResponse As String
 dim i_str as string
 dim ch_i as integer
	ch_i = freefile()
	open "input_file.inp" for input as #ch_i   ' this file will contains many lines of parameter to pass
do while eof(ch_i) = false
 	Line Input #ch_i, i_str
	StrURL = "https://www.target.com/srv.asp"
     	strMSG = "?id1=HeathCheck&id2=123&id3=test" &  i_str
 	StrURL = StrURL & strMSG   ' /* make sure strlURL contains the https and the url cmd. */
    On Error GoTo err_posting
        Set xmlhttp = New WinHttp.WinHttpRequest
        xmlhttp.Open "POST", StrURL, False
        xmlhttp.SetRequestHeader "Host", "timeout-detecting-URL"   ' /* set label in web log */
        xmlhttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        xmlhttp.Send (strMSG) 	'Submit the transaction to the server gateway
        'Wait for response
        XMLResponse = xmlhttp.ResponseText 	'Retrieve the result
        Set xmlhttp = Nothing 	'Destroy the object
	debug.print XMLResponse    ' display the result
    close ch_i
    exit sub
    debug.print err.description
    exit sub
end sub

Open in new window

  • 2
1 Solution
Try moving the on error line to just after  sub main()
It is setting that in the loop currently
mshox1Author Commented:

I tried that ealier,  but it does not works.  (i.e put on error outside the loop.

mshox1Author Commented:
good , thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now