Lua
Lua
POST JSON Without Waiting for the Response
See more REST Examples
This example demonstrates sending a POST w/ content-type "application/json" where the body of the POST contains a JSON document. The POST is sent, but we don't wait for the response.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local rest = chilkat.Rest.new()
-- Connect to the server using TLS
local bAutoReconnect = false
local success = rest:connect("example.com", 443, true, bAutoReconnect)
if not success then
print(rest.last_error_text)
return
end
-- Create some sample JSON to be sent in the body of the request.
local sbJson = chilkat.StringBuilder.new()
sbJson:append("{\"create\": [{\"name\": \"Woo Single #1\",\"type\": \"simple\",\"regular_price\": \"21.99\"}]}")
-- Add the Content-Type HTTP request header.
rest:add_header("Content-Type", "application/json")
-- Just send the request. Don't read the response.
-- The request is sent to https://example.com/something?arg1=xyz&arg2=abc
local somePath = "/something?arg1=xyz&arg2=abc"
success = rest:send_req_sb("POST", somePath, sbJson)
if not success then
print(rest.last_error_text)
return
end
-- OK, the request was sent.
-- Close the connection.
local maxWaitMs = 50
rest:disconnect(maxWaitMs)
print("JSON POST Sent.")