title: http request with consumer key in swift 3.0
body: <p>I am really new to Swift and I'm trying to make a http request to a URL with consumer key and consumer secret and honestly I'm not sure that is even possible to do in Swift.</p>
  
  <p>I've been trying to make this work with authentication method but it only gives me an error.</p>
  
  <p>My code (Hope this helps you to understand what I'm trying to do..)</p>
  
  <pre><code>let baseUrl = "my url"
  let consumer_key = "consumer_key"
  let consumer_secret = "consumer_secret"
  
  let loginString = NSString(format:"%@:%@", consumer_key, consumer_secret)
  let loginData = loginString.data(using: String.Encoding.utf8.rawValue)!
  let base64LoginString = loginData.base64EncodedString()
  
  let url = URL(string: baseUrl)
  var request = URLRequest(url: url!)
  request.httpMethod = "GET"
  request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
  
  let config = URLSessionConfiguration.default
  let authString = "Basic \(base64LoginString)"
  config.httpAdditionalHeaders = ["Authorization" : authString]
  let session = URLSession(configuration: config)
  
   session.dataTask(with: url!) {
       (data, response, error) in
       if (response as? HTTPURLResponse) != nil {
          print("in session")
          let dataString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
          print("data please...",dataString!)
        }
    }.resume()
  </code></pre>
  
  <p>If this http call with consumer key and consumer secret is totally unacceptable in Swift or if there is any other way that I can get by this, please let me know.</p>
  
  <p>Thank you in advanced.</p>
  
  <p>EDIT------------------------------------------------------</p>
  
  <pre><code>import UIKit
  
  
  class OrdersViewController: UIViewController {
  
  
      @IBOutlet weak var orderView: UITableView!
  
      var orderData = [[String: AnyObject]]()
      var selectedIndex = -1
  
      override func viewDidLoad() {
          super.viewDidLoad()
          print("in")
          // Do any additional setup after loading the view.
          let baseUrl = "my url"
          let consumer_key = "consumer_key"
          let consumer_secret = "consumer_secret"
  
          let loginString = NSString(format:"%@:%@", consumer_key, consumer_secret)
          let loginData = loginString.data(using: String.Encoding.utf8.rawValue)!
          let base64LoginString = loginData.base64EncodedString()
  
          let url = URL(string: baseUrl)
          var request = URLRequest(url: url!)
          request.httpMethod = "GET"
          request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
  
          let config = URLSessionConfiguration.default
          let authString = "Basic \(base64LoginString)"
          config.httpAdditionalHeaders = ["Authorization" : authString]
          let session = URLSession(configuration: config)
  
          session.dataTask(with: url!) {
              (data, response, error) in
              if (response as? HTTPURLResponse) != nil {
                  print("in session")
                  let dataString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
                  print("data please...",dataString!)
              }
          }.resume()
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int{
          return orderData.count
      }
  
      func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -&gt; CGFloat {
          if (selectedIndex == indexPath.row) {
              return 100
          } else {
              return 40
          }
      }
  
      func tableView(tableView: UITableView, cellforRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          let cellIdentifier = "Cell"
          let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as! orderCell
  
          let obj = orderData[indexPath.row]
          print("obj", obj)
  
          return cell
      }
  
  }
  </code></pre>