http.post

From ComputerCraft
Jump to: navigation, search

http.post
Function
Syntax
http.post()
Returns table response | boolean false, string error[, table response]
API http
Source CC:Tweaked (source)

Attempt to fetch a webpage using the POST method, using the same arguments as http.request. This will return the response table or false, an error message and (sometimes) a handle with the failing response’s content (specifically, this is included when the actual request succeeded, but the server returned an erroneous HTTP code, e.g. 401: Unauthorized).

The HTTP API assumes Unicode by default, meaning you may run into issues when fetching binary data. To avoid this, set binary to true. You will have to pass something to postData and headers to set the binary flag, e.g. http.post(url, "", nil, true).

ExampleExampleDownloading a page
Requests a single page with some postdata and prints the contents.
Code
-- Make a HTTP request
local request, err = http.post("https://example.computercraft.cc/post", "test=data&one=two")
if not request then error(err) end
-- Print the contents
print(request.readAll())
request.close() -- Don't forget to close!
Output Prints test=data&one=two