title: How to login by POST method or How to access data by POST method
body: <p>I am trying to get data from API with multiple parameter and using Headers.
  i try a lot but not success, problem is that i  can do this using Alamofire. but i want to do it by NSURLSession.</p>
  
  <pre><code>func apiCalling(){
          let myUrl = NSURL(string: "http://203.XXXXXXXXX.php");
          let request = NSMutableURLRequest(URL:myUrl!);
          request.HTTPMethod = "POST";// Compose a query string
          request.addValue("KAISAPAISA", forHTTPHeaderField: "APIXXXXX")
          let postString = "uname=demo&amp;password=demo123";
  
          request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding);
          let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
              data, response, error in
  
              if error != nil
              {
                  print("error=\(error)")
                  return
              }
  
              // You can print out response object
              print("response = \(response)")
  
              // Print out response body
              let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
              print("responseString = \(responseString)")
  
              //Let's convert response sent from a server side script to a NSDictionary object:
              do {
                  let myJSON =  try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as? NSDictionary
  
                  if let parseJSON = myJSON {
  
                      // Now we can access value of First Name by its key
                      let firstNameValue = parseJSON["firstName"] as? String
                      print("firstNameValue: \(firstNameValue)")
                  }
              } catch {
                  print(error)
              }
          }
          task.resume()
  }
  </code></pre>