Main differences compared to HttpRequest:
- It has a Timeout: Seconds Option.
- Cookie
- WinHttp startup with empty cookie, and cookies will saved automatically.
- HttpRequest has two modes:
- By default, it uses Internet Explorer's cookie.
- When +NO_COOKIES option is specified, you need to specify Cookie: header manually.
- NO_AUTO_REDIRECT
- Timeout: Seconds
- Proxy: IP:Port
- Codepage: 65001
- Charset: utf-8
- SaveAs: FileName
- Execute WinHttpRequest( [] )
Code: Select all
r := WinHttpRequest("http://google.com/", InOutData := "", InOutHeaders := Headers(), "Timeout: 1`nNO_AUTO_REDIRECT")
MsgBox, % (r = -1) ? "successful" : (r = 0) ? "Timeout" : "No response"
MsgBox, % InOutData
MsgBox, % InOutHeaders
Return
Headers(referer = "")
{
Headers =
( LTrim
Referer: %referer%
User-Agent: Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.16
)
Return Headers
}
Note: Some old system don't have winhttp.dll, the solution is copy winhttp.dll from other machine, to c:\windows\system32\winhttp.dll, then run regsvr32 winhttp.dll.