如何在不等待响应的情况下从XMLHTTP发送请求? [英] How to send request from XMLHTTP without waiting for the response?

查看:55
本文介绍了如何在不等待响应的情况下从XMLHTTP发送请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pXML= Product_Request
set http= server.Createobject("MSXML2.ServerXMLHTTP")
http.Open "GET", "http://test.com/Data_Check/Request.asp?XML_File=" & pXML , False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send

我需要使用上述asp代码针对上述URL发送请求.但是我不需要来自该服务器的响应.

I need to send request with above asp code for the above URL. But i no need response from that server.

发送请求后,它等待响应. 如何编写该代码,以使其在等待响应时不会阻塞?

After sending the request, it waits for the response. How do I write this so that it doesn't block while waiting for the response?

推荐答案

您也许可以使用

You may be able to use the WinHTTPRequest object directly instead (this is what underlies ServerXMLHTTP). It has an additional method which might be useful the WaitForResponse method.

 Set winHttpRequest = CreateObject("WinHttp.WinHttpRequest.5.1") 
 winHttpRequest.Open "GET", "http://localhost/mypage.aspx", true

 winHttpRequest.Send

 ''# Do other request normally here

 winHttpRequest.WaitForResponse()

请注意,Open方法的async参数具有true.在这种情况下,Send将在发送请求后但未收到任何响应之前返回.现在,您可以执行其他操作,例如以正常的同步方式发出其他请求.完成后,您可以通过调用WaitForResponse来确保原始请求已完成.

Note the Open method has true for its async parameter. In this case Send will return as soon as the request has been sent but before any response has been recieved. You can now do other things like make your other request in a normal synchronous manner. Once done you can make sure that the orginal request has completed by calling WaitForResponse.

注意

  • 我从来没有直接在ASP中完成此操作,有可能对Open的调用可能会抱怨脚本环境没有进行异步调用".
  • 您认为可以同时提出两个请求.如果将它们放在两个不同的服务器上,那将是可以的,即使不是还可以,但是可能还会有其他麻烦.
  • 您正在向ASP页面发出请求,每个请求都会在该服务器上创建一个新会话,这是需要注意的事情.
  • 根据我的假设,如果您使用的是线程池死锁,则您不会调用正在运行代码的服务器.
  • I've never done this on in ASP directly there is possibility that the call to Open might complain that the script environment doesn't "do asynchronous calls".
  • There is an assumption on your part that it is ok to make the two requests at the same time. If they are to two different servers then that will be fine, if not its still possibly fine but there may be other complications.
  • You are making requests to an ASP page, each request creates a new session on that server, just something to be aware of.
  • There is an assumption on my part you aren't calling into the same server that your code is running on, if you are you may be headed for a thread pool dead lock.

这篇关于如何在不等待响应的情况下从XMLHTTP发送请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆