Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

ios - NSURLSession "HTTP load failed kCFStreamErrorDomainSSL, -9813 ; Self signing certificate

I'm trying to connect my iOS app to an HTTPS Rails app which is currently run on a local host in my network. I can access the site from my browser with https://myIP:3000/display as well as in the command line with a curl request. I'm trying to access it from my app using:

class FirstViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //let url = NSURL(string: "https://another/Sinatra/website/feed")
        let url = NSURL(string: "https://myIP:3000/display")

        let request = NSURLRequest(URL: url!)
        let task = NSURLSession.sharedSession().dataTaskWithURL(url!)
        task!.resume()
    }

When I try to access the sinatra website I have no trouble and can even print out the JSON to the console with the correct commands. However, when I set url to my Rails website I get the following error.

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)

In addition, I can tell that my localhost Rails app (on the other machine) is not pinged from the iOS app, but is pinged from the browser and curl command.

Any ideas how to fix this?

question from:https://stackoverflow.com/questions/30791361/nsurlsession-http-load-failed-kcfstreamerrordomainssl-9813-self-signing-cer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If I understood well, Apple now wants the developers to use HTTPS and TLS 1.2 for network calls.

Temporary, you can add this in your "Info.plist" file :

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

Just have a look to this link, it may also help you : http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/

--

Update : Following some comments the above solution is not anymore working. Here is an updated solution.

  1. Go to your Info.plist file.
  2. Add a row of Type Dictionary and of Key App Transport Security Settings.
  3. In this Dictionary, add a row of Type Boolean, of Key Allow Arbitrary Loads and of Value YES

-

Otherwise you can set Domain Exceptions. This is how to do :

  1. Go to your Info.plist file.
  2. Add a row of Type Dictionary and of Key App Transport Security Settings.
  3. Add a row of Type Dictionary and of Key Exception Domains.
  4. Add a row of Type Dictionary and of Key The domain.
  5. Add two rows of Type Boolean and of Key NSExceptionAllowsInsecureHTTPLoads & NSIncludesSubdomains with Value to YES.

Links

https://forums.developer.apple.com/message/5857#5857

2015 WWDC Session 711

iOS 9 HTTP Connection Error - StackOverflow


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...