0

i'm have this parameters on payload to send a POST request to backend

 '{"token":"xxxx", "extra_information": {"expires_in": xxxx, "refresh_token": "xxx", "user_id": "user_uuid", "token_type": "Bearer"}}'

Parameters with "xxxx" will be come by integration. I'm try create a function to send 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,String>

        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 write this xCode show me a error "Cannot convert Value of Type NSDate to expected dictionary value Type String" due to parameter expires_in receive a NSDate.

Edit 1 - After change Dictionay receive strData occured error "Cannot convert value of type 'NSURLResponse to expected argument type 'NSData'"

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

Its because you are casting params as Dictionary <String,String> thats why it will not accept NSDate as value in your dictionary.

You need to change it like Dictionary <String,AnyObject> and it will work.

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165