Name | Webget |
Syntax | webget [<url>] (data:<data>) (method:<method>) (headers:<map>) (timeout:<duration>/{10s}) (savefile:<path>) (hide_failure) |
Short Description | Gets the contents of a web page or API response. |
Full Description | Connects to a webpage or API and downloads its contents, to be used via the save argument and corresponding entry tags.
This should almost always be ~waited for. Refer to ~waitable. Note that while this will replace URL spaces to %20, you are responsible for any other necessary URL encoding. You may want to use the ElementTag.url_encode tag for this. Optionally, use "data:<data>" to specify a set of data to send to the server (changes the default method from GET to POST). A BinaryTag input will be used directly - any other input will be treated as a String and encoded as UTF-8. Optionally, use "method:<method>" to specify the HTTP method to use in your request. Can be: GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE, PATCH. Optionally, use "headers:" to specify a MapTag of headers. Optionally, use "savefile:" to specify a path to save the retrieved file to. This will remove the 'result' entry savedata. Path is relative to server base directory. Optionally, specify the "timeout:" to set how long the command should wait for a webpage to load before giving up. Defaults to 10 seconds. Optionally, specify 'hide_failure' to indicate that connection errors are acceptable and shouldn't display in logs. This command accepts secret inputs via SecretTag as the URL or as the value of any header. Note that you cannot mix secret with non-secret - meaning, "webget <secret[my_secret]>" and "webget https://example.com" are both valid, but "webget https://example.com/<secret[my_secret]>" is not. Similarly, for headers, each individual header value can either be a secret or not a secret. |
Related Tags | <entry[saveName].failed> returns whether the webget failed. A failure occurs when the status is not 2XX/3XX or webget failed to connect.
<entry[saveName].result> returns the text of the result of the webget. This is null only if webget failed to connect to the url.
<entry[saveName].result_binary> returns the raw binary data of the result of the webget. This is null only if webget failed to connect to the url.
<entry[saveName].result_headers> returns a MapTag of the headers returned from the webserver. Every value in the result is a list.
<entry[saveName].status> returns the HTTP status code of the webget. This is null only if webget failed to connect to the url.
<entry[saveName].time_ran> returns a DurationTag indicating how long the web connection processing took.
<ElementTag.url_encode> Encodes the element using URL encoding.
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Usage Example |
|
Synonyms (Search Aid) | wget |
Group | core |
Source | https://github.com/DenizenScript/Denizen-Core/blob/master/src/main/java/com/denizenscript/denizencore/scripts/commands/core/WebGetCommand.java#L39 |