在 VBScript 中检索 Cookie 并发送 Cookie 和 Post 变量

发布于 2024-12-03 02:45:01 字数 929 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲性难收 2024-12-10 02:45:01

您可以通过 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 parsing http.getAllResponseHeaders(). Then, you should add cookie values to request header via http.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文