Project

General

Profile

$urlget » History » Version 12

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