$urlget » History » Revision 10
Revision 9 (Per Amundsen, 07/10/2019 06:14 PM) → Revision 10/16 (Per Amundsen, 07/10/2019 06:18 PM)
_Added in 3.6_ *$urlget(N/id/url,gpfbrtc,target,alias,headers,body)* Performs a GET/POST request to a http server and returns a unique id to identify the request. When the request is finished, calls the specified alias with the id as a parameter. _Files downloaded with the 'f' parameter will use the folder matching the file extension from [[Dcc_Options#Dcc-Get-Folders|Dcc Get Folders]] or the [[Dcc_Options#Default-download-dir|default Dcc Get Folder]]._ *Parameters* N - If N = 0, returns the Nth running request, otherwise the Nth running request. id - Returns the running request matching the id. url - The "url":https://en.wikipedia.org/wiki/URL to perform the GET/POST request to. gpfbrtc: g - Perform a GET request. p - Perform a POST request. f - Save the response to a file. b - Save the response to a &binvar. r - Resume a failed request/download. t - TODO c - Cancel a running request. target - The target &binvar or filename to save the response. alias - The alias to perform when the request is completed. headers - &binvar containing addiotional headers separated by [[$crlf]]. (optional) body - &binvar containing POST data, used with the "p" switch. (optional) *Properties* .url - Returns the url used. .redirect - Returns the value of the location header if available. .method - Returns the method used (GET/POST). .type - Returns the type of output, (binvar/file). .target - Returns the value of target (name of the binvar or filename). .alias - Returns the name of the alias used. .id - Returns the unique request id. .state - Returns the state (ok, connect, download, fail). .size - Returns the value of the Content-Lenght header. .resume - Returns the number of bytes to resume from a failed request/download. .rcvd - Returns the number of bytes received after the header, could be different from .size after a failed download. .time - Returns the time taken to complete the processing, in milliseconds. .reply - Returns the response headers. *Example* <pre> ; Perform a GET request to adiirc.com and put the result in '&target' binvar. //noop $urlget(https://adiirc.com,gb,&target,callback) ; Or Perform a POST request to adiirc.com and put When the result in '&target' binvar. alias posttest { bset -t &header 1 Test: Header bset -t &body 1 foo1=bar1&foo2=bar2 noop $urlget(https://adiirc.com,pb,&target,callback,&header,&body) } ; When a request requested is finished, print the result. alias callback { echo -ag Response: $bvar($urlget($1).target,1-).text } ; List the number of running requests. //echo -ag $urlget(0) ; List the first running request. //echo -ag $urlget(1) ; Cancel the first running request. //echo -ag $urlget(1, c) ; Download the latest AdiIRC beta. ; Notice the 'target' parameter is left blank so it will use the original filename from the server. ; Also notice the 'alias' parameter is set to /noop to ignore the callback. //noop $urlget(https://adiirc.com/AdiIRC64_45.exe,gf,,/noop) </pre>