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

zgqtxwd 2011-09-25 01:15:28
使用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
...全文
1624 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
oh_ku 2011-10-21
  • 打赏
  • 举报
回复
楼主有答案了没,我也想知道
  • 打赏
  • 举报
回复
GetAllResponseHeaders,这样就好了
dahual 2011-09-25
  • 打赏
  • 举报
回复
字符串处理而已,可以自己写个。
'自定义函数,返回数组集合
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

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧