Tcl
Tcl
Send a REST Request with a Text Body
See more REST Examples
Demonstrates Rest.FullRequestString, a convenience method that sends a complete request whose text body (such as JSON, XML, or plain text) is supplied directly, then reads and returns the response body as text.
Background. The full-request convenience methods perform the entire request/response exchange in a single call. FullRequestString is well suited to typical JSON or XML API calls where the body fits comfortably in a string.
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
set rest [new_CkRest]
set bTls 1
set bAutoReconnect 1
set success [CkRest_Connect $rest "example.com" 443 $bTls $bAutoReconnect]
if {$success == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
exit
}
# Send a complete request whose text body is supplied directly, such as JSON. The response body is
# read as text and returned. The 1st argument is the HTTP verb, the 2nd is the URI path, and the
# 3rd is the request body.
CkRest_AddHeader $rest "Content-Type" "application/json"
set jsonBody "{ \"name\": \"example\", \"active\": true }"
set responseText [CkRest_fullRequestString $rest "POST" "/api/items" $jsonBody]
if {[CkRest_get_LastMethodSuccess $rest] == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
exit
}
puts "$responseText"
delete_CkRest $rest