Swift
Swift
Inspect HTTP Request Header
Demonstrates theLastHeader property.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
let http = CkoHttp()!
var url: String? = "https://chilkatsoft.com/echo_request_body.asp"
var json: String? = "{\"greeting\":\"Hello World\"}"
// Send a POST with the JSON in the HTTP request body.
let resp = CkoHttpResponse()!
success = http.httpStr(verb: "POST", url: url, bodyStr: json, charset: "utf-8", contentType: "application/json", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
// Examine the HTTP request header we just sent.
print("\(http.lastHeader!)")
// Output:
// POST /echo_request_body.asp HTTP/1.1
// Host: chilkatsoft.com
// Accept: */*
// Accept-Encoding: gzip
// Content-Type: application/json
// Content-Length: 26
}