无法加载资源,因为应用程序传输安全策略要求使用安全连接
“无法加载资源,因为应用程序传输安全策略要求使用安全连接”
-(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";
连接失败:Error Domain=NSURLErrorDomain Code=-1022“无法加载资源,因为AppTransportSecurity策略要求使用安全连接。UserInfo={NSUnderlyingError=0x7fada0f31880{Error Domain=kCFErrorDomainCFNetwork Code=-1022“(Null)”},NSErrorFailingURLStringKey= MyServiceURL,NSErrorFailingURLKey= MyServiceURL,NSLocalizedDescription=无法加载资源,因为AppTransportSecurity策略要求使用安全连接。}