Project

General

Profile

Actions

$urlget » History » Revision 4

« Previous | Revision 4/16 (diff) | Next »
Per Amundsen, 07/09/2019 08:27 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.

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 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

; 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)

Updated by Per Amundsen over 5 years ago · 4 revisions

Also available in: PDF HTML TXT