(Swift) HTTP POST with Binary Data in Request Body
Do an HTTPS POST with a binary request body. Note: This example requires Chilkat v11.0.0 or greater.
func chilkatTest() {
var success: Bool = false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
let fac = CkoFileAccess()!
var reqBody: NSData
reqBody = fac.readEntireFile("qa_data/pdf/helloWorld.pdf")
let resp = CkoHttpResponse()!
success = http.httpBinary("POST", url: "https://example.com/something", byteData: reqBody, contentType: "application/pdf", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
var responseStatusCode: Int = resp.statusCode.intValue
print("Status code: \(responseStatusCode)")
// For example, if the response is XML, JSON, HTML, etc.
print("response body:")
print("\(resp.bodyStr!)")
}
|