Internet: Difference between revisions
No edit summary |
No edit summary |
||
| Line 55: | Line 55: | ||
|<code>:getStatusCode()</code> | |<code>:getStatusCode()</code> | ||
|<code>int</code> | |<code>int</code> | ||
|Returns the [[wikipedia:List_of_HTTP_status_codes|HTTP status]] code of the response. | |Returns the [[wikipedia:List_of_HTTP_status_codes|HTTP status]] code of the response. Response codes in the 2xx range typically indicate success. | ||
|- | |- | ||
|<code>: | |<code>:getResponseBody()</code> | ||
|<code> | |<code>string</code> | ||
| | |Returns the response body as a string. | ||
|- | |- | ||
|<code>: | |<code>:getResponseBodySize()</code> | ||
|<code> | |<code>int</code> | ||
| | |Returns the length of the string that will be returned by <code>:getResponseBody()</code>. | ||
|- | |||
|<code>:getResponseHeaders()</code> | |||
|<code>table</code> | |||
|Returns a table listing all response headers. Headers with multiple values are concatenated using commas as a delimeter. | |||
|} | |} | ||
{{Navbox content}} | {{Navbox content}} | ||
Revision as of 11:47, 18 August 2026
The InternetUD component allows making real-world HTTP(s) requests. In order to be able to send HTTP(s) requests, make sure the current computer is connected to a WAN Router either directly via Network Cable or indirectly through Network Routers.
Security
By default, requests to local IP addresses are blocked (e.g. http://127.0.0.1). Domains are not filtered. You can allow access to local IPs by disabling the filtering in the config file.
If you wish, HTTP(s) functionality can also be disabled entirely in the config file. This completely removes the ability to make any kind of HTTP(s) requests.
API
| Name | Type | Read/Write | Description |
|---|---|---|---|
isHttpEnabled |
bool |
READ | Returns whether HTTP(s) is enabled at all. True by default, but can be changed in the server's config. Required to be true in order to use any methods. |
isConnectedToWan
|
bool
|
READ | Returns whether the current computer can reach a WAN router via the network. Required to be true in order to use any methods. |
| Name | Returns | Description |
|---|---|---|
:sendHttpRequest(url:string[, method:string[, postData:string[, headers:table]]])
|
HttpResponseUD
|
Asynchronously sends an HTTP(s) request to the given URL with the given request method (e.g. GET, POST, etc.).
If the request method is set to something supporting a post body, you may provide one as a string in |
Handling responses
Upon making an HTTP(s) request you are provided with an HttpResponseUD object offering the following functionality.
| Name | Type | Read/Write | Description |
|---|---|---|---|
responseAvailable |
bool |
READ | Returns whether this HTTP(s) request has been completed and therefore a response is available. |
| Name | Returns | Description |
|---|---|---|
:waitForCompletion()
|
void
|
Blocks until responseAvailable is true. All other functions implicitly call this prior to executing and thus show the same behaviour.
|
:getStatusCode()
|
int
|
Returns the HTTP status code of the response. Response codes in the 2xx range typically indicate success. |
:getResponseBody()
|
string
|
Returns the response body as a string. |
:getResponseBodySize()
|
int
|
Returns the length of the string that will be returned by :getResponseBody().
|
:getResponseHeaders()
|
table
|
Returns a table listing all response headers. Headers with multiple values are concatenated using commas as a delimeter. |