Ward Posted June 7, 2015 Posted June 7, 2015 (edited) Like Request for node.js or Requests for python, Request UDF is a powerful and easy-to-use HTTP client for AutoIt. It is based on my Curl.au3 and Json.au3 (not included). The Features:Request target can be a string (single url), an array (urls), an object (single url + options or url array + options), an object array (urls + different options), or a json string (decode to array or object automatically), etc.Easy to setup post data, cookies, agent, refer, timeout, proxy, etc.Easy to setup the default options before a series of requests.Use BinaryToString() to decode the returned data according to content type automatically. Use curl multi interface by default. It means all requests will transfer simultaneously and won't block the GUI event.Use callback function to recieve the data and information for every url before main function finished.Supports https and ftp protocols.Example:#Include "Json.au3" #Include "Curl.au3" #Include "Request.au3" RequestDefault('{refer: "http://www.autoitscript.com", agent: "AutoIt/Request", callback: "MyCallback"}') Local $Data = Request("http://httpbin.org/get") ConsoleWrite($Data & @LF) Request('["http://www.google.com", "http://wikipedia.org"]') Request('{url: "http://www.google.com", agent: "AutoIt/Request"}') Request('{url: ["http://www.google.com", "http://wikipedia.org"], agent: "AutoIt/Request"}') Local $Array[] = ["http://www.google.com", "http://wikipedia.org"] Request($Array) Request("http://httpbin.org/post", "key=Post%20can%20be%20the%20raw%20data") Request("http://httpbin.org/post", '{key: "Post can be a json object string"}') Request('{url: "http://httpbin.org/post", post:{key: "Post can be set as second paramemtr or \"post\" option"}}') Local $Obj Json_Put($Obj, ".key", "Post can be an object") Local $Json = Request("http://httpbin.org/post", $Obj) Func MyCallback($Obj) Local $Data = Json_ObjGet($Obj, "Data") Local $EffectiveUrl = Json_ObjGet($Obj, "EffectiveUrl") ConsoleWrite("Callback: " & $EffectiveUrl & " download size: " & StringLen($Data) & @LF) EndFuncMore examples are in the archive.Request.zip Edited November 23, 2015 by Ward oHenry and argumentum 2 新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了。
water Posted June 7, 2015 Posted June 7, 2015 Added to the UDF list in the wiki My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
qwert Posted June 7, 2015 Posted June 7, 2015 (edited) @Ward: which is the right BinaryCall.au3? (It's in two of the zips.)I went with the 2015 version and got some undefined fcns.Also, I got the error below. Typo? Edited June 7, 2015 by qwert
water Posted June 7, 2015 Posted June 7, 2015 Shouldn't there be a space character in the last line before "Then $Callback = Execute($Callback)" My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
qwert Posted June 8, 2015 Posted June 8, 2015 Yes, adding a space takes care of that. But has anyone been able to run the example? If so, with which BinaryCall.au3?My attempt is stopped by two missing MemoryModule functions.
argumentum Posted June 8, 2015 Posted June 8, 2015 qwert, change this part in BinaryCallIf $HasMemoryDll Then Local $Module = Execute('__MemoryModule_ModuleRecord("get", Null, $DllName)') If $Module Then Local $MemoryGetProcAddress = Execute('__MemoryModule_RuntimeLoader("MemoryGetProcAddress")') If $MemoryGetProcAddress Then $Proc = DllCallAddress("ptr:cdecl", $MemoryGetProcAddress, "ptr", $Module, "str", $ProcName)[0] If Not $Proc Then Return SetError(2, _BinaryCall_LastError("MemoryGetProcAddress failed on " & $ProcName), False) EndIf EndIf Skysnake 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
qwert Posted June 8, 2015 Posted June 8, 2015 (edited) That took care of it. Using the above example, I got the result shown below.The actions are logged ... but are the downloads actually stored? Edited June 8, 2015 by qwert
argumentum Posted June 8, 2015 Posted June 8, 2015 That took care of it. Using the above example, I got the result shown below.I don't see those returns in Request_Example.au3 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted June 8, 2015 Posted June 8, 2015 oh, ok, 1st post example.here is no writing to disk in Func MyCallback($Obj) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
qwert Posted June 8, 2015 Posted June 8, 2015 What, then, would be an appropriate write statement? I guess I'm asking where is the content for a download and what format is it?Sorry to be so persistent, but this is all brand new to me and I'm trying to get a handle on its use.
argumentum Posted June 8, 2015 Posted June 8, 2015 (edited) What, then, would be an appropriate write statement? I guess I'm asking where is the content for a download and what format is it?Sorry to be so persistent, but this is all brand new to me and I'm trying to get a handle on its use.is plain text. reading the code you could do:Func MyCallback($Obj) Local $Data = Json_ObjGet($Obj, "Data") Local $EffectiveUrl = Json_ObjGet($Obj, "EffectiveUrl") ConsoleWrite('--- '&$Data&' ---'&@LF) ; <--- to see the downloaded data ConsoleWrite("Callback: " & $EffectiveUrl & " download size: " & StringLen($Data) & @LF) EndFuncUnfortunately not everything we find here is for just copy, paste and shine. Read the code. After 700+ posts you should know how.Ward, thanks for sharing, great code. Edited June 8, 2015 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted June 8, 2015 Posted June 8, 2015 (edited) . Edited June 8, 2015 by argumentum the forum entered the post twice Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
qwert Posted June 8, 2015 Posted June 8, 2015 $Data = Json_ObjGet($Obj, "Data")That was the call I needed to see.Thanks for your help. argumentum 1
topten Posted September 3, 2015 Posted September 3, 2015 Thank you very much for such a great UDF. I am just trying to use it#Include "Json.au3" #Include "Curl.au3" #Include "Request.au3" Local $Backup = RequestDefault('{agent: "Autoit/Request", cookiefile: "cookie.txt", cookiejar: "cookie.txt", }') Local $Data = Request('http://www.w3schools.com/html/html_forms.asp') Local $Post Json_Put($Post, ".firstname", "intro") Json_Put($Post, ".lastname", "intro") Local $Obj = Request('{url: "http://www.w3schools.com/html/action_page.php", returnobj: true}', $Post) FileWrite (@DesktopDir & "\3.txt", $Obj)What am I doing wrong in this code? It returns nothingGreat thanx in advance!
recmund Posted November 7, 2015 Posted November 7, 2015 (edited) I needed PUT request for my REST application, so I quickly added CUSTOM_REQUEST support.See cURL MAN page - -X, --request <command> 11c11 < ; Request($Request, $Post = Null) --- > ; Request($Request, $Post = Null, $CustomRequest = Null) 108c108 < Func Request($Request, $Post = Null) --- > Func Request($Request, $Post = Null, $CustomRequest = Null) 179a180,181 > If Not IsKeyword($CustomRequest) Then Json_ObjPut($OptList, "customrequest", $CustomRequest) > 311a314 > If Json_ObjExists($Obj, "customrequest") Then Curl_Easy_Setopt($Curl, $CURLOPT_CUSTOMREQUEST, Json_ObjGet($Obj, "customrequest")) 320a324 > PATCH Request.au3 Edited November 7, 2015 by recmund
recmund Posted November 29, 2015 Posted November 29, 2015 BUGFIX:Custom debug function was not being called.Insert line to 443:If IsString($Debug) And IsFunc(Execute($Debug)) Then $Debug = Execute($Debug)
fairylovehn127 Posted January 8, 2016 Posted January 8, 2016 I needed PUT request for my REST application, so I quickly added CUSTOM_REQUEST support.See cURL MAN page - -X, --request <command> 11c11 < ; Request($Request, $Post = Null) --- > ; Request($Request, $Post = Null, $CustomRequest = Null) 108c108 < Func Request($Request, $Post = Null) --- > Func Request($Request, $Post = Null, $CustomRequest = Null) 179a180,181 > If Not IsKeyword($CustomRequest) Then Json_ObjPut($OptList, "customrequest", $CustomRequest) > 311a314 > If Json_ObjExists($Obj, "customrequest") Then Curl_Easy_Setopt($Curl, $CURLOPT_CUSTOMREQUEST, Json_ObjGet($Obj, "customrequest")) 320a324 > PATCH Request.au3Do you have request.au3 which include cUrl.au3 and json.au3 or where i can download it thanks
argumentum Posted January 8, 2016 Posted January 8, 2016 (edited) On 1/8/2016 at 12:57 PM, fairylovehn127 said: Do you have request.au3 which include cUrl.au3 and json.au3 or where i can download it thanks Edited February 10, 2024 by argumentum removed attachment ( needed space ) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
fairylovehn127 Posted January 9, 2016 Posted January 9, 2016 (edited) What problem with my code, it return unsuccessfull request Edited January 10, 2016 by fairylovehn127
fairylovehn127 Posted January 9, 2016 Posted January 9, 2016 (edited) ok, here they are, from my PC, in Curl there is a folder "changed by argumentum" and you may need the file from there if BinaryCall gives you trouble.As soon as the files are back, I'll remove this post and attached files.Request(2015.06.07).zipCurl(2015.06.04).zipJson(2015.01.08).zipI want to implement curl like that. How can i put a header to curl :(. Edited January 10, 2016 by fairylovehn127
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now