作者为 于 发表
这个函数改自http://www.autohotkey.com/board/topic/101686-objectresponsetext-error/#entry667257
实现的是免文件读写下载网页代码
;示例1 POST数据
url := "http://thinkai.net/test.php"
MsgBox, % URLDownloadToVar(url,"utf-8","POST","a=1&b=2")
;示例2 GET数据
url := "http://thinkai.net/test.php"
MsgBox, % URLDownloadToVar(url "?config=设置","utf-8","GET")
URLDownloadToVar(url, Encoding = "",Method="GET",postData=""){ ;网址,编码,请求方式,post数据
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
try
{
hObject.SetTimeouts(30000,30000,1200000,1200000)
hObject.Open(Method,url,(Method="POST" ? True : False))
hObject.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
if IsObject(headers)
{
for k,v in headers
hObject.SetRequestHeader(k, v)
}
hObject.Send(postData)
if (Method="POST")
hObject.WaitForResponse(-1)
}
catch e
return -1
if (Encoding && hObject.ResponseBody)
{
oADO := ComObjCreate("adodb.stream")
oADO.Type := 1
oADO.Mode := 3
oADO.Open()
oADO.Write(hObject.ResponseBody)
oADO.Position := 0
oADO.Type := 2
oADO.Charset := Encoding
return oADO.ReadText(), oADO.Close()
}
return hObject.ResponseText
}
60 queries in 2.193 seconds |