PureBasic
PureBasic
HttpPostJson2 Example
See more HTTP Examples
Demonstrates use of the HttpPostJson2 method.Chilkat PureBasic Downloads
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 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.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; 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::setCkAcceptCharset(http, "")
CkHttp::setCkUserAgent(http, "")
CkHttp::setCkAcceptLanguage(http, "")
CkHttp::setCkAllowGzip(http, 0)
jsonBody.s = "{" + Chr(34) + "client_id" + Chr(34) + ": " + Chr(34) + "PLAID_CLIENT_ID" + Chr(34) + ", " + Chr(34) + "secret" + Chr(34) + ":" + Chr(34) + "PLAID_SECRET" + Chr(34) + ", " + Chr(34) + "count" + Chr(34) + ": 10, " + Chr(34) + "offset" + Chr(34) + ": 0}"
resp.i = CkHttp::ckPostJson2(http,"https://sandbox.plaid.com/institutions/get","application/json",jsonBody)
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
ProcedureReturn
EndIf
statusCode.i = CkHttpResponse::ckStatusCode(resp)
Debug "Response status code = " + Str(statusCode)
; Examine the JSON response..
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoad(json,CkHttpResponse::ckBodyStr(resp))
CkJsonObject::setCkEmitCompact(json, 0)
Debug "JSON Response Body:"
Debug CkJsonObject::ckEmit(json)
CkHttpResponse::ckDispose(resp)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure