The resource could not be loaded because the Application Transport Security policy requires a secure connection


Manab Kumar

Having trouble updating Xcode to 7.0 or iOS 9.0. Somehow it started giving me the title error

"The resource could not be loaded because the application transport security policy requires the use of a secure connection"

Web service method:

-(void)ServiceCall:(NSString*)ServiceName :(NSString *)DataString
{
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
    [sessionConfiguration setAllowsCellularAccess:YES];
    [sessionConfiguration setHTTPAdditionalHeaders:@{ @"Accept" : @"application/json" }];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",ServiceURL]];
    NSLog(@"URl %@%@",url,DataString);
    // Configure the Request
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setValue:[NSString stringWithFormat:@"%@=%@", strSessName, strSessVal] forHTTPHeaderField:@"Cookie"];
    request.HTTPBody = [DataString dataUsingEncoding:NSUTF8StringEncoding];
    request.HTTPMethod = @"Post";

    // post the request and handle response
    NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
                                          {
                                              // Handle the Response
                                              if(error)
                                              {
                                                  NSLog(@"%@",[NSString stringWithFormat:@"Connection failed: %@", [error description]]);

                                                  // Update the View
                                                  dispatch_async(dispatch_get_main_queue(), ^{

                                                      // Hide the Loader
                                                      [MBProgressHUD hideHUDForView:[[UIApplication sharedApplication] delegate].window animated:YES];


                                                  });
                                                  return;
                                              }
                                              NSArray * cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:request.URL];
                                              for (NSHTTPCookie * cookie in cookies)
                                              {
                                                  NSLog(@"%@=%@", cookie.name, cookie.value);
                                                  strSessName=cookie.name;
                                                  strSessVal=cookie.value;

                                              }

                                              NSString *retVal = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}];
[postDataTask resume];

}

The service was working fine for Xcode earlier versions and iOS earlier versions, but when I updated to Xcode 7.0 on iOS 9.0, it started to have issues like below when I call the above web service method. The logging error I get is:

Connection failed: Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the application transport security policy requires the use of a secure connection." UserInfo={NSUnderlyingError=0x7fada0f31880{Error Domain=kCFErrorDomainCFNetwork Code=-1022"(null)"}, NSErrorFailingURLStringKey= MyServiceURL , NSErrorFailingURLKey= MyServiceURL , NSLocalizedDescription=The resource could not be loaded because the application transport security policy requires the use of a secure security connection. }

I have tried the following questions and answers but got no results, are there any advanced ideas to remove this service call error?

  1. ios9 can't load resource
  2. App Transport Security Xcode 7 Beta 6
  3. https://stackoverflow.com/a/32609970
Manab Kumar

I have solved it by adding some keys in info.plist. The steps I followed are:

  1. Open my project target's info.plistfile

  2. Added a named key NSAppTransportSecurity.Dictionary

  3. Added a subkey called NSAllowsArbitraryLoadsas Booleanand set its value YESas shown in the image below.

enter image description here

Cleaned the project and now everything is running fine as before.

Reference link : https://stackoverflow.com/a/32609970

Edit: or in the source code of the info.plistfile , we can add:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>yourdomain.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
                <false/>
            </dict>
       </dict>
  </dict>

Related


Secure connection using transport client

St. Kaidal Need to connect to secure elasticsearch with https authentication using transport client in java code. I have the user id and password to connect, but need an example of how we do it? I am using elastic search 5.6.0. I'm looking for xpack and shelf

Secure connection using transport client

St. Kaidal Need to connect to secure elasticsearch with https authentication using transport client in java code. I have the user id and password to connect, but need an example of how we do it? I am using elastic search 5.6.0. I'm looking for xpack and shelf

A secure connection could not be established

Sergey Hleb Use : Alamofire 5, self-signed certificate.The certificate is stored in the application resource AlamofireExtension(Bundle.main).certificates- return it. Meeting : private let session: Session = { let manager = ServerTrustManager(evalua

Application transport security issues in Webview

VV I am trying to display http url in webview but getting ATS error below. NSURL *url=[NSURL URLWithString:@"http://stackoverflow.com"]; [_webview loadRequest:[NSURLRequest requestWithURL:url]]; App Transport Security prevents cleartext HTTP (http://) resourc

Refused to load because it violates the Content Security Policy

FreshDev I'm having a very strange issue with "Content Security Policy" in Chrome and Firefox. My meta tags look like this: <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-

Refused to load because it violates the Content Security Policy

FreshDev I'm having a very strange issue with "Content Security Policy" in Chrome and Firefox. My meta tags look like this: <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-

Secure connection between application and server

This Ar: hi i try these codes to connect my ionic app to apiserver (get) import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; @Injectable({ pr

Could not load resource (.resx) file because it is not trusted

Ali Azam Having trouble building Windows source code in Visual Studio 2017. Displays the error message mentioned in the title. Does anyone have any ideas about this error message? Ali Azam Finally, I can solve the following problem: Open File Explorer. Navigat

Could not load resource (.resx) file because it is not trusted

Ali Azam Having trouble building Windows source code in Visual Studio 2017. Displays the error message mentioned in the title. Does anyone have any ideas about this error message? Ali Azam Finally, I can solve the following problem: Open File Explorer. Navigat

Deactivate Azure Security Policy for a specific resource

username How to deactivate Azure Security Policy for a specific resource? Policies should still apply to other resources in the resource group/subscription. Tony Chu Azure policies are assigned to a specific scope ( management group , subscription or resource

Deactivate Azure Security Policy for a specific resource

username How to deactivate Azure Security Policy for a specific resource? Policies should still apply to other resources in the resource group/subscription. Tony Chu Azure policies are assigned to a specific scope ( management group , subscription or resource

Deactivate Azure Security Policy for a specific resource

username How to deactivate Azure Security Policy for a specific resource? Policies should still apply to other resources in the resource group/subscription. Tony Chu Azure policies are assigned to a specific scope ( management group , subscription or resource

pandas to_sql sqlalchemy connection with secure_transport

en_lorithai I'm trying to send data to a mysql database on a server with --require_secure_transport=ON. When I try to connect to it using the following code import pandas as pd import pymysql from sqlalchemy import create_engine connect_string = 'mysql+pymysq

pandas to_sql sqlalchemy connection with secure_transport

en_lorithai I'm trying to send data to a mysql database on a server with --require_secure_transport=ON. When I try to connect to it using the following code import pandas as pd import pymysql from sqlalchemy import create_engine connect_string = 'mysql+pymysq

pandas to_sql sqlalchemy connection with secure_transport

en_lorithai I'm trying to send data to a mysql database on a server with --require_secure_transport=ON. When I try to connect to it using the following code import pandas as pd import pymysql from sqlalchemy import create_engine connect_string = 'mysql+pymysq

pandas to_sql sqlalchemy connection with secure_transport

en_lorithai I'm trying to send data to a mysql database on a server with --require_secure_transport=ON. When I try to connect to it using the following code import pandas as pd import pymysql from sqlalchemy import create_engine connect_string = 'mysql+pymysq

pandas to_sql sqlalchemy connection with secure_transport

en_lorithai I'm trying to send data to a mysql database on a server with --require_secure_transport=ON. When I try to connect to it using the following code import pandas as pd import pymysql from sqlalchemy import create_engine connect_string = 'mysql+pymysq