how to set http timeout using asp?

后端 未结 2 390
庸人自扰
庸人自扰 2021-01-12 06:30

This is my asp code

<%
http = server.createobject(\"microsoft.xmlhttp\")
http.open \"post\", servleturl, false
http.setrequestheader \"content-type\", \"a         


        
相关标签:
2条回答
  • 2021-01-12 06:55

    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
    
    0 讨论(0)
  • 2021-01-12 06:59

    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.

    0 讨论(0)
提交回复
热议问题