$urlget » History » Version 6
Per Amundsen, 07/09/2019 09:17 PM
| 1 | 1 | Per Amundsen | _Added in 3.6_ |
|---|---|---|---|
| 2 | |||
| 3 | *$urlget(N/id/url,gpfbrtc,target,alias,headers,body)* |
||
| 4 | |||
| 5 | 4 | Per Amundsen | Performs a GET/POST request to a http server and returns a unique id to identify the request. |
| 6 | 1 | Per Amundsen | |
| 7 | 4 | Per Amundsen | When the request is finished, calls the specified alias with the id as a parameter. |
| 8 | 1 | Per Amundsen | |
| 9 | *Parameters* |
||
| 10 | |||
| 11 | 3 | Per Amundsen | N - If N = 0, returns the Nth running request, otherwise the Nth running request. |
| 12 | 1 | Per Amundsen | id - Returns the running request matching the id. |
| 13 | |||
| 14 | url - The "url":https://en.wikipedia.org/wiki/URL to perform the GET/POST request to. |
||
| 15 | 2 | Per Amundsen | gpfbrtc: |
| 16 | 1 | Per Amundsen | g - Perform a GET request. |
| 17 | p - Perform a POST request. |
||
| 18 | f - Save the response to a file. |
||
| 19 | b - Save the response to a &binvar. |
||
| 20 | r - Resume a failed request/download. |
||
| 21 | t - TODO |
||
| 22 | c - Cancel a running request. |
||
| 23 | target - The target &binvar or filename to save the response. |
||
| 24 | alias - The alias to perform when the request is completed. |
||
| 25 | headers - &binvar containing addiotional headers separated by [[$crlf]]. (optional) |
||
| 26 | body - &binvar containing POST data, used with the "p" switch. (optional) |
||
| 27 | |||
| 28 | *Properties* |
||
| 29 | |||
| 30 | .url - Returns the url used. |
||
| 31 | .redirect - Returns the value of the location header if available. |
||
| 32 | .method - Returns the method used (GET/POST). |
||
| 33 | .type - Returns the type of output, (binvar/file). |
||
| 34 | .target - Returns the value of target (name of the binvar or filename). |
||
| 35 | .alias - Returns the name of the alias used. |
||
| 36 | 4 | Per Amundsen | .id - Returns the unique request id. |
| 37 | 1 | Per Amundsen | .state - Returns the state (ok, connect, download, fail). |
| 38 | .size - Returns the value of the Content-Lenght header. |
||
| 39 | .resume - Returns the number of bytes to resume from a failed request/download. |
||
| 40 | .rcvd - Returns the number of bytes received after the header, could be different from .size after a failed download. |
||
| 41 | .time - Returns the time taken to complete the processing, in milliseconds. |
||
| 42 | .reply - Returns the response headers. |
||
| 43 | |||
| 44 | *Example* |
||
| 45 | |||
| 46 | <pre> |
||
| 47 | ; Perform a GET request to adiirc.com and put the result in '&target' binvar. |
||
| 48 | //noop $urlget(https://adiirc.com,gb,&target,callback) |
||
| 49 | |||
| 50 | 5 | Per Amundsen | ; When the requested is finished, print the result. |
| 51 | 1 | Per Amundsen | alias callback { |
| 52 | 6 | Per Amundsen | echo -ag Response: $bvar($urlget($1).target,1-).text |
| 53 | 1 | Per Amundsen | } |
| 54 | |||
| 55 | ; List the number of running requests. |
||
| 56 | //echo -ag $urlget(0) |
||
| 57 | |||
| 58 | ; List the first running request. |
||
| 59 | //echo -ag $urlget(1) |
||
| 60 | |||
| 61 | ; Cancel the first running request. |
||
| 62 | //echo -ag $urlget(1, c) |
||
| 63 | </pre> |