title: How do you add headers to dataTaskWithUrl?
body: <p>I have a <code>dataTaskWithUrl</code>:</p>
  
  <pre><code>        var headers: NSDictionary = ["X-Mashape-Key": "my-secret-key" , "Accept" : "application/json"]
          var stringUrl = "https://restcountries-v1.p.mashape.com/all"
          stringUrl = stringUrl.stringByReplacingOccurrencesOfString(" ", withString: "+")
          let url = NSURL(string: stringUrl)
          let session = NSURLSession.sharedSession()
          let task = session.dataTaskWithURL(url!, completionHandler: { (data, response, error) -&gt; Void in
  
          if let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as? NSDictionary{
  
             println(jsonResult)
  
          }else{
              println("error")
          }
  
        })
  
         task.resume()
  </code></pre>
  
  <p>I want to add headers to my task.</p>
  
  <p>In other words, I would like to convert this code to swift:</p>
  
  <pre><code>NSDictionary *headers = @{@"X-Mashape-Key": @"my-secret-key", @"Accept": @"application/json"};
  UNIUrlConnection *asyncConnection = [[UNIRest get:^(UNISimpleRequest *request) {
    [request setUrl:@"https://restcountries-v1.p.mashape.com/all"];
    [request setHeaders:headers];
  }] asJsonAsync:^(UNIHTTPJsonResponse *response, NSError *error) {
    NSInteger code = response.code;
    NSDictionary *responseHeaders = response.headers;
    UNIJsonNode *body = response.body;
    NSData *rawBody = response.rawBody;
  }];
  </code></pre>
  
  <p>I am new to dataRequests. I do not understand Objective C code but I made a guess when I looked at that code. I need to use headers because I if I just try going to 
  <a href="https://restcountries-v1.p.mashape.com/all" rel="noreferrer">https://restcountries-v1.p.mashape.com/all</a> directly, I get an error. I had received that Objective C code from this website: <a href="https://www.mashape.com/fayder/rest-countries-v1" rel="noreferrer">https://www.mashape.com/fayder/rest-countries-v1</a>. Any help in the right direction would be very much appreciated.</p>
  
  <p>Thanks</p>