Autoit实现HTTP GET与POST方法

admin AutoIt3评论2,1471字数 1266阅读模式

想用AU3写使用HTTP协议发送POST,google后在autoit的论坛找到了不错的方法。
有人说用xmlhttp,调用ie,用winhttp等等,还是这个obj操作com的方法简单实用。autoit上的大神写了个库,他命名为WinHttp2.au3。

库:

  1. #include-once  
  2. Global Const $HTTP_STATUS_OK = 200  
  3. Func HttpPost($sURL, $sData = "")  
  4. Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")  
  5. $oHTTP.Open("POST", $sURL, False)  
  6. If (@error) Then Return SetError(100)  
  7. $oHTTP.SetRequestHeader("Content-Type""application/x-www-form-urlencoded")  
  8. $oHTTP.Send($sData)  
  9. If (@error) Then Return SetError(200)  
  10. If ($oHTTP.Status <> $HTTP_STATUS_OK) Then Return SetError(300)  
  11. Return SetError(00, $oHTTP.ResponseText)  
  12. EndFunc  
  13. Func HttpGet($sURL, $sData = "")  
  14. Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")  
  15. $oHTTP.Open("GET", $sURL & "?" & $sData, False)  
  16. If (@error) Then Return SetError(100)  
  17. $oHTTP.Send()  
  18. If (@error) Then Return SetError(200)  
  19. If ($oHTTP.Status <> $HTTP_STATUS_OK) Then Return SetError(300)  
  20. Return SetError(00, $oHTTP.ResponseText)  
  21. EndFunc  

POST方法:

  1. #include "WinHttp2.au3"  
  2. Global $MD5 = HttpPost("http://www.afk-manager.ir/test/post.php""password=WeWantThisAsMd5")  
  3. MsgBox(64"MD5", $MD5)  

GET方法:

  1. #include "WinHttp.au3"  
  2. Global $sGet = HttpGet("http://www.google.com/")  
  3. FileWrite("Google.txt", $sGet)  

更多相关文章

AutoIt3-根目录文件夹检测存在并复制

版权声明:文章图片资源来源于网络,如有侵权,请留言删除!!!
admin
  • 本文由 发表于 2021年2月6日 18:40:15
  • 转载请务必保留本文链接:https://www.58pxe.com/7161.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: