Xbase++ Requires Chilkat v11.1.0+
Xbase++
POST JSON to REST API with non-us-ascii Chars Escaped
See more REST Examples
Demonstrates how to POST to a REST API with non-usascii chars within JSON Unicode escaped.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBAutoReconnect
LOCAL oJson
LOCAL oSb
LOCAL oSbResp
nSuccess := 0
nSuccess := 0
oRest := CreateObject("Chilkat.Rest")
// Connect using TLS.
nBAutoReconnect := 1
nSuccess := oRest:Connect("chilkatsoft.com", 443, 1, nBAutoReconnect)
// Load JSON containing the following Korean text.
// {
// "BillAddr": {
// "Id": "239615",
// "Line1": "류리하",
// "Line2": "류리하류리하",
// "City": "류리하류리하",
// "Country": "US",
// "CountrySubDivisionCode": "AK",
// "PostalCode": "류리하"
// }
// }
oJson := CreateObject("Chilkat.JsonObject")
oJson:EmitCompact := 0
nSuccess := oJson:LoadFile("qa_data/json/korean.json")
IF (nSuccess == 0)
? oJson:LastErrorText
oRest:destroy()
oJson:destroy()
RETURN
ENDIF
nSuccess := oRest:AddHeader("Content-Type", "application/json; charset=UTF-8")
oSb := CreateObject("Chilkat.StringBuilder")
oJson:EmitSb(oSb)
oSb:Encode("unicodeescape", "utf-8")
? oSb:GetAsString()
// The StringBuilder contains this:
// {
// "BillAddr": {
// "Id": "239615",
// "Line1": "\ub958\ub9ac\ud558",
// "Line2": "\ub958\ub9ac\ud558\ub958\ub9ac\ud558",
// "City": "\ub958\ub9ac\ud558\ub958\ub9ac\ud558",
// "Country": "US",
// "CountrySubDivisionCode": "AK",
// "PostalCode": "\ub958\ub9ac\ud558"
// }
// }
oSbResp := CreateObject("Chilkat.StringBuilder")
nSuccess := oRest:FullRequestSb("POST", "/echo_request_body.asp", oSb, oSbResp)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
oJson:destroy()
oSb:destroy()
oSbResp:destroy()
RETURN
ENDIF
// Show the response.
? "Json Response: " + oSbResp:GetAsString()
oRest:destroy()
oJson:destroy()
oSb:destroy()
oSbResp:destroy()