WinHttpRequest POST XML数据示例 Autohotkey | Thinkai's Blog

Thinkai's Blog

Autohoutkey|Python|php|aardio|VOIP|IT 爱好者

WinHttpRequest POST XML数据示例 Autohotkey 1283

作者为 发表

Autohotkey

xml =
(
<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><commonUtil xmlns="http://wtp"><value xmlns:SOAPSDK4="http://wtp">data</value></commonUtil></SOAP-ENV:Body>
)
;请求头根据实际需求修改,注意Content-Type。
result := URLDownloadToVar("http://yourwebsite.com", "UTF-8","POST",xml,{"SOAPAction":"""urn:commonUtil""","Content-Type":"text/xml; charset=""UTF-8""","User-Agent":"SOAP Toolkit 3.0","Host":"0.0.0.0","Content-Length":strlen(xml),"Connection":"Keep-Alive","Cache-Control":"no-cache","Pragma":"no-cache"})
MsgBox % result

URLDownloadToVar(url, Encoding = "",Method="GET",postData="",headers:=""){ ;网址,编码,请求方式,post数据,请求头
	hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	if Method = GET
	{
		Try
		{
			;hObject.SetTimeouts(500,2000,2000,5000)
			hObject.Open("GET",url)
			hObject.Send()
		}
		catch e
			return -1
	}
	else if Method = POST
	{
		Try
		{
			hObject.SetTimeouts(30000,30000,300000,300000)
			hObject.Open("POST",url,True)
			if IsObject(headers)
			{
				for k,v in headers
				hObject.SetRequestHeader(k, v)
			}
			hObject.Send(postData)
			hObject.WaitForResponse(-1)
		}
		catch e
		{
			FileAppend, % "`n" var_dump(e), error.txt
			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
}



来了就留个评论吧! 没有评论




友情链接:Autohotkey中文论坛Autohotkey中文帮助Autohotkey官网我的B站直播间如若生涯一场梦博客联系作者免GooglePlay APK下载

 主题设计 • skyfrit.com  Thinkai's Blog | 保留所有权利

63 queries in 1.441 seconds |