当前位置:编程学习 > VB >>

GetResponseHeader如何取得服务器返回的多个[set-cookie]问题!

使用WinHttp.WinHttpRequest.5.1控件,读取数据时返回多行set-cookie

但是用.GetResponseHeader("Set-Cookie")只能读取到每一行

如何取到每二个Set-Cookie,第三个Set-Cookie呢?



以下为返回的头信息
HTTP/1.1 200 OK
Date: Sat, 24 Sep 2011 22:17:26 GMT
Server: xxx Login Server/2.0.0
P3P: CP="CAO PSA OUR"
Set-Cookie: ads=12331414; ads=Fri, 02-Jan-2010 00:00:00 GMT; PATH=/; DOMAIN=xxx.com;
Set-Cookie: uin=3213120414; PATH=/; DOMAIN=xxx.com;
Set-Cookie: aes=@SpAofUf9z; PATH=/; DOMAIN=xxx.com;


可以QQ或QQ邮箱上告诉我哦!63272765 --------------------编程问答-------------------- 字符串处理而已,可以自己写个。
'自定义函数,返回数组集合
Function GetResponseHeader(ResponseHeaders,Header)
Dim hs,h
Dim fs
Dim rs(),rc
hs=Split(ResponseHeaders,vbCrLf)
ReDim rs(UBound(hs))
For Each h In hs
If Len(h)>0 Then 
fs=Split(h,": ")
If StrComp(fs(0),Header,vbTextCompare)=0 Then
rs(rc)=fs(1)
rc=rc+1
End If
End If
Next

If (rc>0) Then
ReDim Preserve rs(rc-1)
GetResponseHeader=rs
End If
End Function


'示例
Dim r,v
Dim HttpRequest
Set HttpRequest=CreateObject("WinHttp.WinHttpRequest.5.1")'WinHttp.WinHttpRequest.5.1
With HttpRequest
.Open "GET","http://www.163.com"
.Send
r=GetResponseHeader(.GetAllResponseHeaders(),"Vary")
If IsEmpty(r) Then
MsgBox "未找到!"
Else
For Each v In r
MsgBox v
Next
End If
End With
Set HttpRequest=Nothing
--------------------编程问答-------------------- GetAllResponseHeaders,这样就好了 --------------------编程问答-------------------- 楼主有答案了没,我也想知道
补充:VB ,  网络编程
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,