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 POST x-www-form-urlencodedDemonstrates how to send a simple x-www-form-urlencoded POST.
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkFileAccess.pb" IncludeFile "CkHttpRequest.pb" Procedure ChilkatExample() http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf jsonStr.s = "{ some json ... }" req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; This query parameter just happens to be named "json" and contains JSON text. CkHttpRequest::ckAddParam(req,"json",jsonStr) ; We can optionally add more query parameters. CkHttpRequest::ckAddParam(req,"abc","123") CkHttpRequest::ckAddParam(req,"xml","<abc>123</abc>") ; Note: Just because we passed a query param named "json" or "xml" means nothing special. It's still just ; a name=value query parameter.. resp.i = CkHttp::ckPostUrlEncoded(http,"http://example.net/cirrus/connect/report",req) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) ProcedureReturn EndIf If CkHttpResponse::ckStatusCode(resp) <> 200 Debug "Hey, I didn't receive the expected response status code!" Debug "status code = " + Str(CkHttpResponse::ckStatusCode(resp)) EndIf ; Could be error text if the status code wasn't what we expected, or could be the response ; body you're seeking.. responseBody.s = CkHttpResponse::ckBodyStr(resp) Debug responseBody fac.i = CkFileAccess::ckCreate() If fac.i = 0 Debug "Failed to create object." ProcedureReturn EndIf filepath.s = "some file path" success.i = CkFileAccess::ckWriteEntireTextFile(fac,filepath,responseBody,"utf-8",0) If success <> 1 Debug CkFileAccess::ckLastErrorText(fac) EndIf CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkFileAccess::ckDispose(fac) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.