Swift
Swift
Send HTTPS POST with XML Body
See more HTTP Examples
Demonstrates how to send an HTTP (or HTTPS) POST where the body of the request is XML.Chilkat Swift Downloads
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(name: "Accept", value: "application/xml")
let resp = CkoHttpResponse()!
success = http.httpStr(verb: "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!)")
}