PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BAutoReconnect
oleobject loo_Json
oleobject loo_Sb
oleobject loo_SbResp
li_Success = 0
li_Success = 0
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
// Connect using TLS.
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("chilkatsoft.com",443,1,li_BAutoReconnect)
// Load JSON containing the following Korean text.
// {
// "BillAddr": {
// "Id": "239615",
// "Line1": "류리하",
// "Line2": "류리하류리하",
// "City": "류리하류리하",
// "Country": "US",
// "CountrySubDivisionCode": "AK",
// "PostalCode": "류리하"
// }
// }
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.EmitCompact = 0
li_Success = loo_Json.LoadFile("qa_data/json/korean.json")
if li_Success = 0 then
Write-Debug loo_Json.LastErrorText
destroy loo_Rest
destroy loo_Json
return
end if
li_Success = loo_Rest.AddHeader("Content-Type","application/json; charset=UTF-8")
loo_Sb = create oleobject
li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder")
loo_Json.EmitSb(loo_Sb)
loo_Sb.Encode("unicodeescape","utf-8")
Write-Debug loo_Sb.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"
// }
// }
loo_SbResp = create oleobject
li_rc = loo_SbResp.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Rest.FullRequestSb("POST","/echo_request_body.asp",loo_Sb,loo_SbResp)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_Json
destroy loo_Sb
destroy loo_SbResp
return
end if
// Show the response.
Write-Debug "Json Response: " + loo_SbResp.GetAsString()
destroy loo_Rest
destroy loo_Json
destroy loo_Sb
destroy loo_SbResp