Swift
Swift
HTTP POST with Binary Data in Request Body
See more HTTP Examples
Do an HTTPS POST with a binary request body.Chilkat Swift Downloads
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(path: "qa_data/pdf/helloWorld.pdf")
let resp = CkoHttpResponse()!
success = http.httpBinary(verb: "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!)")
}