(Swift) Send HTTPS POST with XML Body
Demonstrates how to send an HTTP (or HTTPS) POST where the body of the request is XML. Note: This example requires Chilkat v11.0.0 or greater.
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
var strXml: String? = "<TransactionSetup xmlns=\"https://xyz.com\"><Credentials><AccountID>XXX</AccountID></Credentials></TransactionSetup>"
// Maybe you need other headers?
http.setRequestHeader("Accept", value: "application/xml")
let resp = CkoHttpResponse()!
success = http.httpStr("POST", url: "https://www.somewebsite.com/", bodyStr: strXml, charset: "utf-8", contentType: "application/xml", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
// Examine the response status code:
print("response status code = \(resp.statusCode.intValue)")
// Examine the response body:
print("response body: \(resp.bodyStr!)")
}
|