Project

General

Profile

$urlget » History » Revision 2

Revision 1 (Per Amundsen, 07/09/2019 08:24 PM) → Revision 2/16 (Per Amundsen, 07/09/2019 08:24 PM)

_Added in 3.6_ 

 *$urlget(N/id/url,gpfbrtc,target,alias,headers,body)* 

 Performs a GET/POST request to a http server. Returns a unique ID to identify the request.  

 When the request is finished, calls the specified alias with the ID as a parameter. 

 *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: 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) 

 ; When the requested is finished, print the result 
 alias callback { 
   echo -ag Response: $bvar($urlget(%id).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) 
 </pre>