Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set http timeout using asp?

This is my asp code

<%
http = server.createobject("microsoft.xmlhttp")
http.open "post", servleturl, false
http.setrequestheader "content-type", "application/x-www-form-urlencoded"
http.setrequestheader "accept-encoding", "gzip, deflate"
http.send  "request=" & sxml
http_response = http.responsetext
%>

i need to make TimeOut when the response not come in 15 seconds how?

like image 929
user475464 Avatar asked Dec 27 '12 09:12

user475464


2 Answers

You can also keep using the synchronous request by calling "SetTimeouts" like this:

<%
Dim http

Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
http.SetTimeouts 600000, 600000, 15000, 15000
http.Open "post", servleturl, false
http.SetRequestHeader "content-type", "application/x-www-form-urlencoded"
http.SetRequestHeader "accept-encoding", "gzip, deflate"
http.Send  "request=" & sxml

http_response = http.responsetext
%>

See here for docs.

The parameters are:

setTimeouts (long resolveTimeout, long connectTimeout, long sendTimeout, long receiveTimeout)

The setTimeouts method should be called before the open method. None of the parameters is optional.

like image 92
gpinkas Avatar answered Sep 27 '22 20:09

gpinkas


Using waitForResponse method of ServerXMLHTTP instance after the .Send call is a proper way, I'd recommend.
Also to use .WaitForResponse, need to make an asynchronous call by setting True the third parameter of .Open method.

Const WAIT_TIMEOUT = 15
Dim http
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
    http.open "POST", servleturl, True 'async request
    http.setrequestheader "content-type", "application/x-www-form-urlencoded"
    http.setrequestheader "accept-encoding", "gzip, deflate"
    http.send  "request=" & sxml
    If http.waitForResponse(WAIT_TIMEOUT) Then 'response ready
        http_response = http.responseText
    Else 'wait timeout exceeded
        'Handling timeout etc
        'http_response = "TIMEOUT" 
    End If
Set http = Nothing
like image 41
Kul-Tigin Avatar answered Sep 27 '22 19:09

Kul-Tigin