Sample code for 30+ languages & platforms
Tcl

HttpPostJson2 Example

See more HTTP Examples

Demonstrates use of the HttpPostJson2 method.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

# This requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code

# See PostJson2Async Example for the async equivalent of this example.

set http [new_CkHttp]

# Sends a POST equivalent to the following CURL command:

# curl -X POST https://sandbox.plaid.com/institutions/get \
#   -H 'content-type: application/json' \
#   -d '{
#     "client_id": String,
#     "secret":String,
#     "count": Number,
#     "offset": Number
#   }'

# Suppress some default headers that would automatically added..
CkHttp_put_AcceptCharset $http ""
CkHttp_put_UserAgent $http ""
CkHttp_put_AcceptLanguage $http ""
CkHttp_put_AllowGzip $http 0

set jsonBody "{\"client_id\": \"PLAID_CLIENT_ID\", \"secret\":\"PLAID_SECRET\", \"count\": 10, \"offset\": 0}"
# resp is a CkHttpResponse
set resp [CkHttp_PostJson2 $http "https://sandbox.plaid.com/institutions/get" "application/json" $jsonBody]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    exit
}

set statusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response status code = $statusCode"

# Examine the JSON response..
set json [new_CkJsonObject]

CkJsonObject_Load $json [CkHttpResponse_bodyStr $resp]
CkJsonObject_put_EmitCompact $json 0
puts "JSON Response Body:"
puts [CkJsonObject_emit $json]

delete_CkHttpResponse $resp


delete_CkHttp $http
delete_CkJsonObject $json