(Swift) Example: Http.HttpBinary method
Demonstrates the HttpBinary method. Note: This example requires Chilkat v11.0.0 or greater.
func chilkatTest() {
var success: Bool = false
var localFilePath: String? = "C:/example/zips/data.zip"
let bd = CkoBinData()!
success = bd.loadFile(localFilePath)
if success == false {
print("\(bd.lastErrorText!)")
return
}
var zipBytes: NSData
zipBytes = bd.getData()
var url: String? = "https://example.com/api/v1/sites/123/deploys"
// Send a POST with a binary HTTP request body.
let resp = CkoHttpResponse()!
let http = CkoHttp()!
success = http.httpBinary("POST", url: url, byteData: zipBytes, contentType: "application/zip", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
print("Response Status Code: \(resp.statusCode.intValue)")
print("Response body:")
print("\(resp.bodyStr!)")
}
|