title: Make a http request with basic authentication
body: <p>I want to make an http request with basic auth. I tried to follow this topic : <a href="https://stackoverflow.com/questions/24379601/how-to-make-an-http-request-basic-auth-in-swift?s=4%7C0.6752">click here</a>. But Xcode tell me </p>
  
  <blockquote>
    <p>Bad Request after httpResponse</p>
  </blockquote>
  
  <p>And I don't know why since this morning. Maybe anyone got a idea more interesting than I can find on the web ? :)</p>
  
  <p>Here is my code :</p>
  
  <pre><code>func topRefresh(sender:AnyObject){
  
      var list=Array&lt;Notification&gt;()
  
      //credential
      let credentialLogin = NSUserDefaults.standardUserDefaults().objectForKey("login") as! String
      let credentialPassword = NSUserDefaults.standardUserDefaults().objectForKey("password") as! String
  
      // set up the base64-encoded credentials
      let loginString = NSString(format: "%@:%@", credentialLogin, credentialPassword)
      let loginData: NSData = loginString.dataUsingEncoding(NSUTF8StringEncoding)!
      let base64LoginString = loginData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
  
      // create the request
      let url = NSURL(string: jsonLink)!
      let request = NSMutableURLRequest(URL: url)
      request.cachePolicy = NSURLRequestCachePolicy.ReloadIgnoringCacheData
      request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
      request.HTTPMethod="GET"
      let paramString="login="+credentialLogin
      request.HTTPBody = paramString.dataUsingEncoding(NSUTF8StringEncoding)
  
      let session = NSURLSession.sharedSession()
      let task = session.dataTaskWithRequest(request) {
          (data, response, error) -&gt; Void in
  
          let httpResponse = response as! NSHTTPURLResponse
  
          if (httpResponse.statusCode == 200) {
              do{
                  if  (data != nil){
                      self.notificationsDisplayed.removeAll()
                      let jsonDict = try NSJSONSerialization.JSONObjectWithData(data!,options: .AllowFragments)
                      list=self.parseJson(jsonDict)
  
                      if (self.notifications.count==0){
                          self.notifications=self.copyArray(list)
                          list.removeAll()
                      }else{
                          //compare new data with past data
                          while(list.count&gt;0){
                              print(list.count)
  
                              let tmp=list.last
                              for notification in self.notifications {
                                  if(tmp!.id==notification.id){
                                      list.removeLast()
                                      break
                                  }else{
                                      self.notifications.insert(tmp!, atIndex: 0)
                                      list.removeLast()
                                      break
                                  }
                              }
                          }
                      }
                      self.orderByDate(&amp;self.notifications)
                      self.notificationsDisplayed=self.copyArray(self.notifications)
                      self.applyFilter()
                      print("Data parsed")
                  }else{
                      print("Data is empty")
                  }
  
              }catch {
                  print("Error with Json: \(error)")
              }
          }else{
              print("HTTP Error")
          }
          self.refreshControl?.endRefreshing()
          print("Finished")
      }
      task.resume()
  }
  </code></pre>