Hi,
My application is doing a normal HTTP request that goes through a proxy server. The proxy server returns a response with some error code when the authenticaton fails. But when I make a request from my app, I am getting the following error "Error in service call The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 310.)". What does this error mean? I want to perform a task upon proxy authentication failure. How could I achieve that?
Below is my code snippet:
NSString* proxyHost = @"aa:bb:cc:dd";
NSNumber* proxyPort = [NSNumber numberWithInt: 80];
NSDictionary *proxyDict = @{
@"HTTPEnable" : [NSNumber numberWithInt:1],
(NSString *)kCFStreamPropertyHTTPProxyHost : proxyHost,
(NSString *)kCFStreamPropertyHTTPProxyPort : proxyPort,
@"HTTPSEnable" : [NSNumber numberWithInt:1],
(NSString *)kCFStreamPropertyHTTPSProxyHost : proxyHost,
(NSString *)kCFStreamPropertyHTTPSProxyPort : proxyPort,
};
NSURLSessionConfiguration *configuration1 = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration1.connectionProxyDictionary = proxyDict;
NSString *proxyUsername = @"username";
NSString *proxypassword = @"password";
NSString *authenticationString = [NSString stringWithFormat:@"%@:%@", proxyUsername, proxypassword];
NSData *authenticationData = [authenticationString dataUsingEncoding:NSASCIIStringEncoding];
NSString *authenticationValue = [authenticationData base64Encoding];
authenticationValue = [@"Basic " stringByAppendingString:authenticationValue];
[request setValue:authenticationValue forHTTPHeaderField:@"Proxy-Authorization"];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration1 delegate:self delegateQueue:nil];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"error is %@",error);
NSLog(@"NSURLSession got the response [%@]", response);
NSLog(@"NSURLSession got the data [%@]", data);
}];
[dataTask resume];
Thanks in advance!!
Just wanted to say thank you so much, your code helped me a lot 🙏🏻