$urlget » History » Version 10
Per Amundsen, 07/10/2019 06:18 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 | 7 | Per Amundsen | _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]]._ |
| 10 | |||
| 11 | 1 | Per Amundsen | *Parameters* |
| 12 | |||
| 13 | 3 | Per Amundsen | N - If N = 0, returns the Nth running request, otherwise the Nth running request. |
| 14 | 1 | Per Amundsen | id - Returns the running request matching the id. |
| 15 | |||
| 16 | url - The "url":https://en.wikipedia.org/wiki/URL to perform the GET/POST request to. |
||
| 17 | 2 | Per Amundsen | gpfbrtc: |
| 18 | 1 | Per Amundsen | g - Perform a GET request. |
| 19 | p - Perform a POST request. |
||
| 20 | f - Save the response to a file. |
||
| 21 | b - Save the response to a &binvar. |
||
| 22 | r - Resume a failed request/download. |
||
| 23 | t - TODO |
||
| 24 | c - Cancel a running request. |
||
| 25 | target - The target &binvar or filename to save the response. |
||
| 26 | alias - The alias to perform when the request is completed. |
||
| 27 | headers - &binvar containing addiotional headers separated by [[$crlf]]. (optional) |
||
| 28 | body - &binvar containing POST data, used with the "p" switch. (optional) |
||
| 29 | |||
| 30 | *Properties* |
||
| 31 | |||
| 32 | .url - Returns the url used. |
||
| 33 | .redirect - Returns the value of the location header if available. |
||
| 34 | .method - Returns the method used (GET/POST). |
||
| 35 | .type - Returns the type of output, (binvar/file). |
||
| 36 | .target - Returns the value of target (name of the binvar or filename). |
||
| 37 | .alias - Returns the name of the alias used. |
||
| 38 | 4 | Per Amundsen | .id - Returns the unique request id. |
| 39 | 1 | Per Amundsen | .state - Returns the state (ok, connect, download, fail). |
| 40 | .size - Returns the value of the Content-Lenght header. |
||
| 41 | .resume - Returns the number of bytes to resume from a failed request/download. |
||
| 42 | .rcvd - Returns the number of bytes received after the header, could be different from .size after a failed download. |
||
| 43 | .time - Returns the time taken to complete the processing, in milliseconds. |
||
| 44 | .reply - Returns the response headers. |
||
| 45 | |||
| 46 | *Example* |
||
| 47 | |||
| 48 | <pre> |
||
| 49 | ; Perform a GET request to adiirc.com and put the result in '&target' binvar. |
||
| 50 | //noop $urlget(https://adiirc.com,gb,&target,callback) |
||
| 51 | |||
| 52 | 10 | Per Amundsen | ; Or Perform a POST request to adiirc.com and put the result in '&target' binvar. |
| 53 | alias posttest { |
||
| 54 | bset -t &header 1 Test: Header |
||
| 55 | bset -t &body 1 foo1=bar1&foo2=bar2 |
||
| 56 | noop $urlget(https://adiirc.com,pb,&target,callback,&header,&body) |
||
| 57 | } |
||
| 58 | |||
| 59 | ; When a request is finished, print the result. |
||
| 60 | 1 | Per Amundsen | alias callback { |
| 61 | 6 | Per Amundsen | echo -ag Response: $bvar($urlget($1).target,1-).text |
| 62 | 1 | Per Amundsen | } |
| 63 | |||
| 64 | ; List the number of running requests. |
||
| 65 | //echo -ag $urlget(0) |
||
| 66 | |||
| 67 | ; List the first running request. |
||
| 68 | //echo -ag $urlget(1) |
||
| 69 | |||
| 70 | ; Cancel the first running request. |
||
| 71 | //echo -ag $urlget(1, c) |
||
| 72 | 8 | Per Amundsen | |
| 73 | ; Download the latest AdiIRC beta. |
||
| 74 | ; Notice the 'target' parameter is left blank so it will use the original filename from the server. |
||
| 75 | 9 | Per Amundsen | ; Also notice the 'alias' parameter is set to /noop to ignore the callback. |
| 76 | 8 | Per Amundsen | //noop $urlget(https://adiirc.com/AdiIRC64_45.exe,gf,,/noop) |
| 77 | 1 | Per Amundsen | </pre> |