在 VBScript 中检索 Cookie 并发送 Cookie 和 Post 变量
我正在尝试使用 vbscript 提交一些帖子数据表单。我将其发布到的网站包含一些 java,并且在标头中进行了查看,我注意到它正在发送一个包含 JSESSIONID
的 cookie,我相信这与 java 身份验证有关:
Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXX
当我只是发送我想要发送的地址和发布数据,并查看它发送回 java 身份验证页面的响应文本,这让我认为我需要检索 jsessionid cookie 并将其与数据一起提交回来。
这是我用来提交帖子数据的函数。对于简单的表单,这似乎工作得很好,但是这个页面上的 java 有点让我困惑:
Function Fetch(URL, POST)
Set WshShell = CreateObject("WScript.Shell")
Set http = CreateObject("Microsoft.XmlHttp")
http.open "POST", URL, FALSE
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send POST
Fetch = http.responseText
set WshShell = nothing
set http = nothing
End Function
我的问题实际上是:如何正确执行此操作?我是否需要加载第一页、获取 cookie 并将其与表单一起重新提交回来?如果是这样,我如何检索服务器在标头中发回的 cookie?当我查看他们发回的标题时我可以看到:
Set-Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXX; Path=/Page
非常感谢。
I'm trying to submit some post data form using vbscript. The site I'm posting it to contains some java, and having poked around in the headers, I notice it's sending a cookie containing JSESSIONID
, which I believe is to do with the java authentication:
Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXX
When I just send the address and the post data I want to send and look at the responsetext it's sent me back to the java authentication page, which makes me think I need to retrieve the jsessionid cookie and submit that back with the data as well.
This is the function I'm using to submit the post data. For simple forms this seems to work fine, but the java on this page has kind of thrown me:
Function Fetch(URL, POST)
Set WshShell = CreateObject("WScript.Shell")
Set http = CreateObject("Microsoft.XmlHttp")
http.open "POST", URL, FALSE
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send POST
Fetch = http.responseText
set WshShell = nothing
set http = nothing
End Function
My questions really are: am how doing this right? Do I need to load the first page, get the cookie and resubmit it back with the form? And if so, how do I retrieve the cookie that the server sends back in the header? I can see when I look in the headers that they sent back:
Set-Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXX; Path=/Page
Thanks very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过
http.getResponseHeader("Set-Cookie")
或解析http.getAllResponseHeaders()
获取。然后,您应该在下次请求时通过http.setRequestHeader "Cookie", "JSESSIONID=XXXXXXXXXXXXXXXXXXXXX; Path=/Page"
将 Cookie 值添加到请求标头。因此,还有另一种选择(如果我没记错的话),使用 CreateObject("WinHttp.WinHttpRequest.5.1") 。
只要您使用该对象的同一实例,该对象就会保留以前使用的 cookie。
You could get via
http.getResponseHeader("Set-Cookie")
or parsinghttp.getAllResponseHeaders()
. Then, you should add cookie values to request header viahttp.setRequestHeader "Cookie", "JSESSIONID=XXXXXXXXXXXXXXXXXXXXX; Path=/Page"
on next requests.So, there is another option (if i'm not wrong), using
CreateObject("WinHttp.WinHttpRequest.5.1")
.The object will retain the cookies previously used as long as you use the same instance of that object.