![]() |
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
(PowerBuilder) HTTP POST x-www-form-urlencodedDemonstrates how to send a simple x-www-form-urlencoded POST. Note: This example requires Chilkat v11.0.0 or greater.
integer li_rc integer li_Success oleobject loo_Http string ls_JsonStr oleobject loo_Req oleobject loo_Resp string ls_ResponseBody oleobject loo_Fac string ls_Filepath li_Success = 0 loo_Http = create oleobject li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if ls_JsonStr = "{ some json ... }" loo_Req = create oleobject li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest") // This query parameter just happens to be named "json" and contains JSON text. loo_Req.AddParam("json",ls_JsonStr) // We can optionally add more query parameters. loo_Req.AddParam("abc","123") loo_Req.AddParam("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.. loo_Req.HttpVerb = "POST" loo_Req.ContentType = "application/x-www-form-urlencoded" loo_Resp = create oleobject li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse") li_Success = loo_Http.HttpReq("http://example.com/xyz/connect/report",loo_Req,loo_Resp) if li_Success = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_Req destroy loo_Resp return end if if loo_Resp.StatusCode <> 200 then Write-Debug "Hey, I didn't receive the expected response status code!" Write-Debug "status code = " + string(loo_Resp.StatusCode) end if // Could be error text if the status code wasn't what we expected, or could be the response // body you're seeking.. ls_ResponseBody = loo_Resp.BodyStr Write-Debug ls_ResponseBody loo_Fac = create oleobject li_rc = loo_Fac.ConnectToNewObject("Chilkat.FileAccess") ls_Filepath = "some file path" li_Success = loo_Fac.WriteEntireTextFile(ls_Filepath,ls_ResponseBody,"utf-8",0) if li_Success <> 1 then Write-Debug loo_Fac.LastErrorText end if destroy loo_Http destroy loo_Req destroy loo_Resp destroy loo_Fac |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.