3 big problems of Msxml2.XMLHTTP
Posted: 19 Sep 2015, 04:06
Msxml2.XMLHTTP is similar to WinHttp.WinHttpRequest.5.1, BUT there are 3 big problems you should know:
- It's not be able to redirect to different domain.
For example, the url http://alturl.com/it3jp will redirect to http://example.com/Code: Select all
req := ComObjCreate("Msxml2.XMLHTTP") req.open("GET", "http://alturl.com/it3jp", False) req.Send() MsgBox, % req.responseText "`n" req.getAllResponseHeaders() ; Get nothing
- It's not be able to set Referer header.
req.SetRequestHeader("Referer", "http://example.com/") just doesn't work, you can try it yourself. - It will caching the contents of the URL page.
Which means if you request the same URL more than once, you always get the same responseText even the website changes text every time.
Example:With some Googling, I found two solutions.Code: Select all
req := ComObjCreate("Msxml2.XMLHTTP") Loop, 3 { req.open("GET", "http://tmplinshi.sinaapp.com/test/time.php", False) req.Send() MsgBox, % req.responseText ; You'll get the same time each time. }
- Add a random parameter to the url.
Code: Select all
req := ComObjCreate("Msxml2.XMLHTTP") Loop, 3 { r := ComObjCreate("Scriptlet.TypeLib").Guid req.open("GET", "http://tmplinshi.sinaapp.com/test/time.php?r=" r, False) req.Send() MsgBox, % req.responseText }
- Set cache related headers.
Code: Select all
req := ComObjCreate("Msxml2.XMLHTTP") Loop, 3 { req.open("GET", "http://tmplinshi.sinaapp.com/test/time.php", False) ;req.SetRequestHeader("Pragma", "no-cache") ;req.SetRequestHeader("Cache-Control", "no-cache") req.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT") req.Send() MsgBox, % req.responseText }
- Add a random parameter to the url.