Swift
Swift
Transition from Http.SynchronousRequest to Http.HttpSReq
Provides instructions for replacing deprecated SynchronousRequest method calls with HttpSReq.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
let http = CkoHttp()!
var domain: String? = "example.com"
var port: Int = 443
var tls: Int = true
let req = CkoHttpRequest()!
req.httpVerb = "POST"
req.path = "/some/path"
req.contentType = "application/x-www-form-urlencoded"
req.addParam(name: "firstName", value: "Matt")
req.addParam(name: "lastName", value: "Smith")
// ------------------------------------------------------------------------
// The SynchronousRequest method is deprecated:
var responseObj: CkoHttpResponse? = http.synchronousRequest(domain: domain, port: port, ssl: tls, req: req)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
// ...
// ...
responseObj = nil
// ------------------------------------------------------------------------
// Do the equivalent using HttpSReq.
// Your application creates a new, empty HttpResponse object which is passed
// in the last argument and filled upon success.
let responseOut = CkoHttpResponse()!
success = http.httpSReq(domain: domain, port: port, ssl: tls, request: req, response: responseOut)
if success == false {
print("\(http.lastErrorText!)")
return
}
}