我认为这可能是一个简单的问题,但我只是有点卡住了。
我正在使用此vbscript函数打开网页并获取cookie。
Function Fetch(URL)
Set WshShell = CreateObject("WScript.Shell")
Set http = CreateObject("Microsoft.XmlHttp")
http.open "", URL, FALSE
Fetch = http.getResponseHeader("Set-Cookie")
set WshShell = nothing
set http = nothing
End Function
它适用于返回一个cookie,但我遇到了一个创建两个cookie的页面,我需要它们。当我使用它时,它只返回第一个cookie。如何退回两个cookie?
非常感谢
答案 0 :(得分:3)
应该自己编写:
Option Explicit
Function Fetch(ByVal URL, ByVal sHdrName)
Dim http
Set http = CreateObject("Microsoft.XmlHttp")
http.open "GET", URL, False
http.Send
Fetch = getHeaders(http, sHdrName)
Set http = Nothing
End Function
Function getHeaders(oReq, sHdrName)
Dim tHdrName : tHdrName = Trim(sHdrName) & ": "
Dim tArr : tArr = Split(oReq.getAllResponseHeaders(), vbCrLf)
tArr = Filter(tArr, tHdrName, True, vbTextCompare)
Dim i
For i = 0 To UBound(tArr)
tArr(i) = Mid(tArr(i), Len(tHdrName) + 1, Len(tArr(i)))
Next
getHeaders = tArr 'Returns Array
End Function
'Iterate & Fetch
Dim iHdrVal
For Each iHdrVal In Fetch("http://a.url", "Set-Cookie")
WScript.Echo iHdrVal
Next