let parameters = ["UserEmail":userMailID, "DeviceUDID": stringUDID] as Dictionary<String, String>
let url = NSURL (string: "Your URL") //change the url
let request = NSMutableURLRequest(URL: url!)
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration(), delegate: nil, delegateQueue: NSOperationQueue.mainQueue())
request.HTTPMethod = "POST" //set http method as POST
request.HTTPBody = try! NSJSONSerialization.dataWithJSONObject(parameters, options: [])
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
// request.timeoutInterval = 100
let task = session.dataTaskWithRequest(request)
{
data, response, error in
guard data != nil else
{
// Error response
}
//RESPONSE HEADER RESULT
let httpsResponse = response as? NSHTTPURLResponse
let str = httpsResponse!.allHeaderFields as NSDictionary
let tokenStr = str["TokenAPI"] as! String
GlobalData.sharedManager.tokenAPI = tokenStr
let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding)
self.json = try NSJSONSerialization.JSONObjectWithData ((jsonStr?.dataUsingEncoding(NSUTF8StringEncoding)!)!, options: .AllowFragments)
Print(self.json)
}
task.resume()
No comments:
Post a Comment