(Swift) qa.factura1.com.co Obtain Auth Token
Demonstrates how to send a JSON POST to get an authenticataion token for qa.factura1.com.co
func chilkatTest() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
// Build the following JSON
// {
// "password": "MY_PASSWORD",
// "username": "MY_USERNAME"
// }
let json = CkoJsonObject()!
json.emitCompact = false
json.update("password", value: "MY_PASSWORD")
json.update("username", value: "MY_USERNAME")
var resp: CkoHttpResponse? = http.postJson3("https://qa.factura1.com.co/v2/auth", contentType: "application/json", json: json)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
let jsonResp = CkoJsonObject()!
jsonResp.emitCompact = false
jsonResp.load(resp!.bodyStr)
resp = nil
print("\(jsonResp.emit()!)")
print("Access token: \(jsonResp.string(of: "token")!)")
}
|