Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) HTTP PUT JSONDemonstrates how to send a JSON PUT and get the JSON response body.
IncludeFile "CkHttpRequest.pb" IncludeFile "CkHttp.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; The PUT request to be sent will look like this: ; PUT /request HTTP/1.1 ; Content-Type: application/jsonrequest ; Cookie: JSESSIONID=1234 ; Content-Encoding: identity ; Host: json.penzance.org ; Accept: application/jsonrequest ; Accept-Encoding: ; Content-Length: 72 ; ; {"user":"doctoravatar@penzance.com","forecast":7,"t":"vlIj","zip":94089} ; First, remove default header fields that would be automatically ; sent. (These headers are harmless, and shouldn't need to ; be suppressed, but just in case...) CkHttp::setCkAcceptCharset(http, "") CkHttp::setCkUserAgent(http, "") CkHttp::setCkAcceptLanguage(http, "") ; Suppress the Accept-Encoding header by disallowing ; a gzip response: CkHttp::setCkAllowGzip(http, 0) ; If a Cookie needs to be added... CkHttp::ckSetRequestHeader(http,"Cookie","JSESSIONID=1234") ; Add the Content-Encoding: identity header. CkHttp::ckSetRequestHeader(http,"Content-Encoding","identity") ; Modify the default "Accept" header: CkHttp::setCkAccept(http, "application/jsonrequest") jsonText.s = "{" + Chr(34) + "user" + Chr(34) + ":" + Chr(34) + "doctoravatar@penzance.com" + Chr(34) + "," + Chr(34) + "forecast" + Chr(34) + ":7," + Chr(34) + "t" + Chr(34) + ":" + Chr(34) + "vlIj" + Chr(34) + "," + Chr(34) + "zip" + Chr(34) + ":94089}" ; To use SSL/TLS, simply use "https://" in the URL. ; IMPORTANT: Make sure to change the URL, JSON text, ; and other data items to your own values. The URL used ; in this example will not actually work. responseBody.s = CkHttp::ckPutText(http,"http://json.penzance.org/request",jsonText,"utf-8","application/jsonrequest",0,0) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) Else ; Display the JSON response. Debug responseBody EndIf CkHttpRequest::ckDispose(req) CkHttp::ckDispose(http) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.