Ran
Ran

Reputation: 303

After set Allow Arbitrary Loads,my http request still got the error message Transport Security has blocked a cleartext

I set the Allow Arbitrary Loads option to YES, allow all http request .But when i run app,It still got an error message "Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file." I do really know, it is not recommend...

enter image description here

NSString *path=[[NSString alloc] initWithFormat:@"/su"];
NSMutableDictionary *param=[[NSMutableDictionary  alloc] init];
[param setValue:@"facebook" forKey:@"wd"];
MKNetworkEngine *engine=[[MKNetworkEngine alloc] initWithHostName:@"suggestion.baidu.com" customHeaderFields:nil];
MKNetworkOperation *op=[engine operationWithPath:path params:param httpMethod:@"get" ssl:NO];
[op addCompletionHandler:^(MKNetworkOperation *completedOperation) {

} errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
    NSLog(@"error");
}];
[engine enqueueOperation:op];

Upvotes: 1

Views: 1863

Answers (2)

Freek Sanders
Freek Sanders

Reputation: 1257

I had a similar issue.
The second key overwrites the first. When I deleted the Allow Arbitrary Loads in Web Content option it started working.
Obviously the Allow Arbitrary should be left on YES

You're probably using iOS > 10.0 or macOS > 10.12.

Version-specific ATS behavior: In a current operating system, the presence of a fine-grained transport security key (NSAllowsArbitraryLoadsForMedia, NSAllowsArbitraryLoadsInWebContent, or NSAllowsLocalNetworking) overrides the value of the NSAllowsArbitraryLoads key to NO. This allows you to set NSAllowsArbitraryLoads to YES if needed for your app in older operating systems, without disabling ATS generally in current operating systems.

https://developer.apple.com

Upvotes: 3

Ran
Ran

Reputation: 303

After I set the exception domain,It works! But It means the Allow Arbitrary Loads doesn't works?

Upvotes: 0

Related Questions