title: NSURLSession With Basic Authentication Challenge
body: <p>I searched all the solution avaliable in stackoverflow. Still confused with this.<br>
  Please point me if i am doing any mistake. I am getting 401 error.</p>
  
  <pre><code>NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL        URLWithString:@"http://qa.api.xxxxxx.com/v0/jobs/93033"]];
  NSString *authStr = @"xxxxxxxx:xxxxxxxxxxx";
  NSData *authData = [authStr dataUsingEncoding:NSUTF8StringEncoding];
  NSString *authValue = [NSString stringWithFormat:@"Basic %@",[authData base64EncodedStringWithOptions:0]];
  [request setValue:authValue forHTTPHeaderField:@"Authorization"];
  request.HTTPMethod = @"GET";
  [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  [request addValue:@"application/json" forHTTPHeaderField:@"Accept"];
  //create the task
  NSURLSessionDataTask* task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
      NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
      if (httpResponse.statusCode == 200)
      {
          NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
          NSLog(@"%@",json);
          dispatch_async(dispatch_get_main_queue(), ^{
          });
      } else {
          // failure: do something else on failure
          NSLog(@"httpResponse code: %@", [NSString stringWithFormat:@"%ld", (unsigned long)httpResponse.statusCode]);
          NSLog(@"httpResponse head: %@", httpResponse.allHeaderFields);
          return;
      }
  
  }];
  
  [task resume];
  </code></pre>