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.
You could get via
http.getResponseHeader("Set-Cookie")
or parsinghttp.getAllResponseHeaders()
. Then, you should add cookie values to request header viahttp.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")
.It's capable to remember the cookies had previously to use on next requests as long as you use the same instance.