Solved

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

Posted on 2009-06-29
3
359 Views
Last Modified: 2012-05-07
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.

thanks


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
 
	loop
finish:
    close ch_i
    exit sub
 
err_posting:
 
    debug.print err.description
 
    exit sub
end sub

Open in new window

0
Comment
Question by:mshox1
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
hes earned 500 total points
ID: 24749176
Try moving the on error line to just after  sub main()
It is setting that in the loop currently
0
 

Author Comment

by:mshox1
ID: 24749621
hes,

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

0
 

Author Closing Comment

by:mshox1
ID: 31598190
good , thank you
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 52
Question about INSTR  - need to extract data MS ACCESS query 6 59
Copy a row 12 64
Problem to With line 4 63
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question