1
I’m with that body to make a POST
to the backend
'{"token":"xxxx", "extra_information": {"expires_in": xxxx, "refresh_token": "xxx", "user_id": "user_uuid", "token_type": "Bearer"}}'
The parameters that are with "xxxx" will come from an integration, with this, I made a function for this.
func sendAuth() {
if let url = NSURL(string: "https://xxxxxxxxxxxx"){
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
let token = AccessToken?()
let params = ["token" : (token?.tokenString)!, "refresh_token" : (token?.refreshToken)!,"expires_in" : (token?.expirationDate)!, "user_id" : "uber_uuid" , "token_type" : "Bearer"] as Dictionary <String,AnyObject>
let httpData = NSKeyedArchiver.archivedDataWithRootObject(params)
request.HTTPBody = httpData
let session = ServicesUtils.BaseSessionManager()
session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
var strData = NSString(data: data, encoding: NSUTF8StringEncoding)
print("\(strData)")
}).resume()
After you have done the parameters correctly the xcode
is appearing the following error:
"Cannot Convert value of type 'Nsurlresponse to expected argument type 'Nsdata"
Could someone help me with this problem?
I believe it’s on the line let httpData = NSKeyedArchiver.archivedDataWithRootObject(params)
that the error starts but I don’t know how to make another syntax to work the code .
thanks for the answer ;) . Just one question: in jsonObject I would need to pass the data that are in the instance
let token = AcessToken()
doing the way Oce answered would be done the POST without passing this data?– rodrigoandrade
@Annihilatorz I just put a string any pro example, of course you need to put the value of your String token in the dictionary. Don’t forget to unwrap the value using if Let.
– Leo Dabus