如题,先上代码:
#include <WinHTTP.au3>
$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, "www.baidu.com")
$hRequest = _WinHttpOpenRequest($hConnect, "head", "")
_WinHttpSendRequest($hRequest)
_WinHttpReceiveResponse($hRequest)
Global $sHeader
If _WinHttpQueryDataAvailable($hRequest) Then $sHeader = _WinHttpQueryHeaders($hRequest)
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
ConsoleWrite($sHeader & @CRLF)
MsgBox(0, "Header", $sHeader)
获取到的head信息如下:HTTP/1.1 200 OK
Date: Sat, 23 Aug 2014 07:48:38 GMT
Content-Type: text/html; charset=utf-8
Connection: Keep-Alive
Vary: Accept-Encoding
Set-Cookie: BAIDUID=87BB6A4D9B1D25C9C063398B714D3022:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
Set-Cookie: BDSVRTM=0; path=/
Set-Cookie: BD_HOME=0; path=/
P3P: CP=" OTI DSP COR IVA OUR IND COM "
Cache-Control: private
Cxy_all: baidu+92a440d6771fa89fc215700bd8f04a92
Expires: Sat, 23 Aug 2014 07:48:18 GMT
X-Powered-By: HPHP
Server: BWS/1.1
BDPAGETYPE: 1
BDQID: 0xfb20ae2a000514ce
BDUSERID: 0
如果我只想获取其中的Content-Type段或者Cache-Control段,而不是全部获取,当然是不用正则的方式,是用winhttp的方法。不知道可不可以实现。
另外还有另一个问题,就是winhttp的异步模式是如何实现的。 |