title: Swift: How to request a URL with a self-signed certificate?
body: <p>I'm opening an SSL connection to retrieve JSON in Swift, but am testing against my own server with a self-signed certificate. Here's a snippet of the URL request:</p>
  
  <pre><code>var urlPath = "https://myhost.com/get_json"
  var url: NSURL = NSURL(string: urlPath)
  var request: NSURLRequest = NSURLRequest(URL: url)
  var connection: NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: false)        
  connection.start()
  </code></pre>
  
  <p>However, it gets rejected (correctly) because of the certificate:</p>
  
  <pre><code>Opening connection to https://myhost.com/get_json
  2014-06-05 09:37:02.543 AppName[44835:3182593] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
  Connection failed.The certificate for this server is invalid. You might be connecting to a server that is pretending to be “myhost.com” which could put your confidential information at risk.## Heading ##
  </code></pre>