本帖最后由 redapple2008 于 2020-9-1 13:46 编辑 Func _XmlHttp($httpurl, $data = "", $type = "", $charset = "", $ContentType = "")
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
If $type = "" Or $type = "POST" Then
$stype = "POST"
Else
$stype = "GET"
EndIf
$oHTTP.Open($stype, $httpurl, True)
$oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134")
$oHTTP.SetRequestHeader("Accept-Language", "zh-CN,zh;q=0.8")
$oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
$oHTTP.SetRequestHeader("Connection", "Close")
If $ContentType = "json" Then
$ContentTypes = "application/json"
ElseIf $ContentType = "xml" Then
$ContentTypes = "text/xml"
ElseIf $ContentType = "formdata" Then
$ContentTypes = "multipart/form-data"
ElseIf $ContentType = "" Then
$ContentTypes = "application/x-www-form-urlencoded"
EndIf
If $charset = "" Or $charset = "UTF-8" Then
$charsets = "UTF-8"
Else
$charsets = "GBK"
EndIf
$oHTTP.SetRequestHeader("Content-Type", $ContentTypes & '; charset=' & $charsets)
$oHTTP.SetRequestHeader("Cache-Control", "no-cache")
$oHTTP.Send($data)
$oHTTP.WaitForResponse()
$oReturnWebS = BinaryToString($oHTTP.ResponseBody, 4)
Return $oReturnWebS
EndFunc ;==>_XmlHttp
$oHTTP.Send() $oHTTP^ ?? 这一句总是出错,怎么解决?#include <GUIConstantsEX.au3>
AccessURL()
Exit
Func AccessURL()
Local $sURL = "http://www.what21.com"
; 创建一个简单的输入界面
GUICreate("内容窗口 ", 640, 480);
Local $idGUIEdit = GUICtrlCreateEdit("HTTP 调用展示 HTML:" & @CRLF, 10, 10, 600, 400);
; 显示 GUI
GUISetState()
; 执行HTTP GET 调用
Local $oHttpObj = ObjCreate("winhttp.winhttprequest.5.1");
; 这里也可以用 GET 或者 POST调用
$oHttpObj.open("POST", $sURL);
$oHttpObj.send();
Local $sHTMLSource = $oHttpObj.Responsetext;
; 将内容填入控件中
GUICtrlSetData($idGUIEdit, "HTML地址 " & $sURL & " 内容:" & @CRLF & @CRLF & StringAddCR($sHTMLSource), "append")
; 等待 知道关闭框口
Local $iMsg
While 1
$iMsg = GUIGetMsg()
If $iMsg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
EndFunc
就这也出错。
|