Http:put(uri, content)method
Send an asynchronous PUT request to the connected HTTP server to creates a new resource or replaces a representation of the target resource.
Parameters
uri
A stringrepresenting the target resource on the server.
content
A File or any value converted to a string representing the body content of the request.
Return value
This method return a Task instance. Once the Task has finished, it will return two values :
- The first value is the Http instance used for the PUT request.
- The second value is
nilin case of error or atablethat contains the server response, with the following fields "content": astringcontaining the body part of the HTTP response"elapsed": anumberrepresenting the elapsed time to get the response"status": anumbercontaining the HTTP response status"reason": astringcontaining HTTP response status text"ok": abooleanvalue indicating if the GET request succeeded"headers": atablecontaining a pair ofstrings(header field names of the HTTP response as key and content as values)"cookies": atablecontaining a pair ofstrings(cookies names of the HTTP response as key and content as values)
Example
--! luart-extensions
import net
local client = net.Http("https://httpbun.com")
local data ="Hello World !"
-- make a PUT request, and once its terminated, call the provided function, to process the response
client:put("/put", data).after = function (self, response)
if not response then
error(net.error)
end
print(response.content)
end
waitall()