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