Susilo Susilo - 8 days ago 7
PHP Question

Fails to send cookies on http request

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

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

The vbscript code:

Dim http
set http = WScript.CreateObject("MSXML2.XMLHTTP")
http.open "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
http://localhost/echo/index.php
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:

Array
(
[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?

Answer

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

Dim http 
set http =  WScript.CreateObject("WinHTTP.WinHTTPRequest.5.1")
http.open "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
Comments