haijie1223 发表于 2014-8-23 16:01:32

如何用winhttp的方法获取head信息的某一段[已解决]

如题,先上代码:
#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的异步模式是如何实现的。

www378660084 发表于 2014-8-23 17:19:04

本帖最后由 www378660084 于 2014-8-23 17:20 编辑

看下这个.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384102%28v=vs.85%29.aspx


pwszName

    Pointer to a string that contains the header name. If the flag in dwInfoLevel is not WINHTTP_QUERY_CUSTOM, set this parameter to WINHTTP_HEADER_NAME_BY_INDEX.

komaau3 发表于 2014-8-23 20:33:00

发哥好执着

Content-Type:
$sHeader = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_TYPE)
Cache-Control:
$WINHTTP_QUERY_CACHE_CONTROL

http://msdn.microsoft.com/en-us/library/aa384070(v=vs.85).aspx

haijie1223 发表于 2014-8-24 20:00:11

回复 3# komaau3


    让阿婆见笑了!鄙人脑袋愚钝,不认真学习怎么会有进步?
winhttp api的异步模式如何实现,还请指点~
页: [1]
查看完整版本: 如何用winhttp的方法获取head信息的某一段[已解决]