本文介绍了在 VBScript 中检索 Cookie 和发送 Cookie 和发布变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 vbscript 提交一些发布数据表单.我将它发布到的站点包含一些 Java,并且在标头中戳了一下,我注意到它正在发送一个包含 JSESSIONID 的 cookie,我认为这与 java 身份验证有关:

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

当我只发送我想发送的地址和发布数据并查看响应文本时,它将我发送回 java 身份验证页面,这让我觉得我需要检索 jsessionid cookie 并将其与数据一起提交

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.

这是我用来提交帖子数据的函数.对于简单的表单,这似乎工作正常,但是此页面上的 java 有点让我感到困惑:

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

我的问题真的是:这件事怎么做是对的?我是否需要加载第一页,获取 cookie 并与表单一起重新提交?如果是这样,我如何检索服务器在标头中发回的 cookie?当我查看他们发回的标题时,我可以看到:

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

非常感谢.

推荐答案

你可以通过 http.getResponseHeader("Set-Cookie") 或者解析 http.getAllResponseHeaders() 获取代码>.然后,您应该在下一个请求中通过 http.setRequestHeaders "Cookie", "JSESSIONID=XXXXXXXXXXXXXXXXXXXXX; Path=/Page" 将 cookie 值添加到请求头中.
所以,还有另一种选择(如果我没记错的话),使用 CreateObject("WinHttp.WinHttpRequest.5.1").

You could get via http.getResponseHeader("Set-Cookie") or parsing http.getAllResponseHeaders(). Then, you should add cookie values to request header via http.setRequestHeaders "Cookie", "JSESSIONID=XXXXXXXXXXXXXXXXXXXXX; Path=/Page" on next requests.
So, there is another option (if i'm not wrong), using CreateObject("WinHttp.WinHttpRequest.5.1").

只要您使用相同的实例,它就能够记住之前必须在下一个请求中使用的 cookie.

It's capable to remember the cookies had previously to use on next requests as long as you use the same instance.

这篇关于在 VBScript 中检索 Cookie 和发送 Cookie 和发布变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:28