|  | 
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
| (Swift) 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. 
 func chilkatTest() { var success: Bool = false let http = CkoHttp()! var jsonStr: String? = "{ some json ... }" let req = CkoHttpRequest()! // This query parameter just happens to be named "json" and contains JSON text. req.addParam("json", value: jsonStr) // We can optionally add more query parameters. req.addParam("abc", value: "123") req.addParam("xml", value: "<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.. req.httpVerb = "POST" req.contentType = "application/x-www-form-urlencoded" let resp = CkoHttpResponse()! success = http.httpReq("http://example.com/xyz/connect/report", request: req, response: resp) if success == false { print("\(http.lastErrorText!)") return } if resp.statusCode.intValue != 200 { print("Hey, I didn't receive the expected response status code!") print("status code = \(resp.statusCode.intValue)") } // Could be error text if the status code wasn't what we expected, or could be the response // body you're seeking.. var responseBody: String? = resp.bodyStr print("\(responseBody!)") let fac = CkoFileAccess()! var filepath: String? = "some file path" success = fac.writeEntireTextFile(filepath, fileData: responseBody, charset: "utf-8", includePreamble: false) if success != true { print("\(fac.lastErrorText!)") } } | ||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.