![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) POST JSON to REST API with non-us-ascii Chars EscapedSee more REST ExamplesDemonstrates how to POST to a REST API with non-usascii chars within JSON Unicode escaped.Note: This example requires Chilkat v11.1.0 or greater.
load ./chilkat.dll set success 0 set success 0 set rest [new_CkRest] # Connect using TLS. set bAutoReconnect 1 set success [CkRest_Connect $rest "chilkatsoft.com" 443 1 $bAutoReconnect] # Load JSON containing the following Korean text. # { # "BillAddr": { # "Id": "239615", # "Line1": "류리하", # "Line2": "류리하류리하", # "City": "류리하류리하", # "Country": "US", # "CountrySubDivisionCode": "AK", # "PostalCode": "류리하" # } # } set json [new_CkJsonObject] CkJsonObject_put_EmitCompact $json 0 set success [CkJsonObject_LoadFile $json "qa_data/json/korean.json"] if {$success == 0} then { puts [CkJsonObject_lastErrorText $json] delete_CkRest $rest delete_CkJsonObject $json exit } set success [CkRest_AddHeader $rest "Content-Type" "application/json; charset=UTF-8"] set sb [new_CkStringBuilder] CkJsonObject_EmitSb $json $sb CkStringBuilder_Encode $sb "unicodeescape" "utf-8" puts [CkStringBuilder_getAsString $sb] # 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" # } # } set sbResp [new_CkStringBuilder] set success [CkRest_FullRequestSb $rest "POST" "/echo_request_body.asp" $sb $sbResp] if {$success == 0} then { puts [CkRest_lastErrorText $rest] delete_CkRest $rest delete_CkJsonObject $json delete_CkStringBuilder $sb delete_CkStringBuilder $sbResp exit } # Show the response. puts "Json Response: [CkStringBuilder_getAsString $sbResp]" delete_CkRest $rest delete_CkJsonObject $json delete_CkStringBuilder $sb delete_CkStringBuilder $sbResp |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.