Http:put(uri, content)


Send an asynchronous PUT request to the connected HTTP server to creates a new resource or replaces a representation of the target resource.

Sending the PUT request and receiveing the HTTP response is done by a Task asynchronously (other Tasks will be executed concurrently without blocking execution flow)

Parameters

uri

A string representing the target resource on the server.

content

A string or a File representing the content of the target resource on the server.

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 nil in case of error or a table that contains the server response, with the following fields
    • "content" : a string containing the body part of the HTTP response
    • "elapsed" : a number representing the elapsed time to get the response
    • "status" : a number containing the HTTP response status
    • "reason" : a string containing HTTP response status text
    • "ok" : a boolean value indicating if the GET request succeeded
    • "headers" : a table containing a pair of strings(header field names of the HTTP response as key and content as values)
    • "cookies" : a table containing a pair of strings(cookies names of the HTTP response as key and content as values)

Example

local net = require "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()