React Native XMLHttpRequest request fails if ssl (https) certificate is not valid

后端 未结 3 386
轻奢々
轻奢々 2021-01-21 00:29

When i am doing XMLHttpRequest to https server with not valid certificate React Native throws exception \"The operation couldn’t be completed. (NSURLErrorDomain error -1202.)\"<

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 00:44

    That's happening because of the new App Transport Security (ATS) feature in iOS 9 (and 8.4 too). ATS was put in place make sure that your app comforms to the best practices for secure connections. If you are hitting this error it means that you are not using a secure connection and you should really do something about this.

    However, you can override the default behavior by editing the Info.plist file of your application.

    There are many different flags that you can set and they are all described in an Apple official technote.

    The simplest modification that will let you turn off ATS all together is the following one:

    1. Open your project in Xcode
    2. On the left, where all the files for your project are listed search for Info.plist
    3. Right click on that file and select Open as > Source Code
    4. Add the following piece of code to under the first tag

    You should really really really not leave this here if you plan on releasing your app.

    NSAppTransportSecurity
        
            NSAllowsArbitraryLoads
            
        
    

提交回复
热议问题