Susilo Susilo - 2 months ago 23
PHP Question

Fails to send cookies on http request

I have vbscript code that send an ajax request to server with cookie using

object. I have read about this bug and workaround. By invoking
twice, cookies should properly sent..but that not happening..

The vbscript code:

Dim http
set http = WScript.CreateObject("MSXML2.XMLHTTP") "POST", "http://localhost/echo", false
http.setRequestHeader "X-Requested-With", "XMLHttpRequest"
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "Cookie", "SESSID=f3rds19k7qu58pvmb80561dc76" '1st invoke '
http.setRequestHeader "Cookie", "SESSID=f3rds19k7qu58pvmb80561dc76" '2nd invoke '
http.send sReq

msgbox http.responseText

And on server side at
contains code

<?php print_r(getallheaders());?>

that php code basically only echoing the request header back to the client, and even I invoke twice this what I got:

[Accept] => */*
[X-Requested-With] => XMLHttpRequest
[Accept-Language] => id
[Accept-Encoding] => gzip, deflate
[User-Agent] => Mozilla/4.0 (bla..bla..bla...)
[Host] => localhost
[Connection] => Keep-Alive
[Cache-Control] => no-cache

As you can see no cookie on the header. How to make cookie sent properly to server?


Finally i found solution... simple.. just use WinHTTP.WinHTTPRequest instead of MSXML2.XMLHTTP

Dim http 
set http =  WScript.CreateObject("WinHTTP.WinHTTPRequest.5.1") "POST", "http://localhost/echo", false
http.setRequestHeader "X-Requested-With", "XMLHttpRequest"
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "Cookie", "SESSID=f3rds19k7qu58pvmb80561dc76"

msgbox http.responseText