问题描述
我正在尝试使用vbscript以编程方式通过Web表单提交一些帖子数据。我发布它的网站包含一些java,并且在标题中戳了一下,我注意到它发送了一个包含JSESSIONID的cookie,我认为这与java身份验证有关:
I'm trying to programatically submit some post data through a web 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
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;路径= / Page
Set-Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXX; Path=/Page
非常感谢。
推荐答案
你可以通过 http.getResponseHeader(Set-Cookie)
或解析 http.getAllResponseHeaders()
。然后,您应该在下次请求时通过 http.setRequestHeadersCookie,JSESSIONID = XXXXXXXXXXXXXXXXXXXX; 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和发布变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!