Hi, I am trying to direct all the requests made by the webview through a proxy by implementing a custom HTTP protocol. Below is my code snippet:
- (void)startLoading {
/------------BEGIN ATTACHING PROXY TO THE REQUEST-----------*/
NSString* proxyHost = @"xx.xx.xx.xx";
NSNumber* proxyPort = [NSNumber numberWithInt: 8080];
NSDictionary *proxyDict = @{
@"HTTPEnable" : [NSNumber numberWithInt:1],
(NSString *)kCFStreamPropertyHTTPProxyHost : proxyHost,
(NSString *)kCFStreamPropertyHTTPProxyPort : proxyPort,
@"HTTPSEnable" : [NSNumber numberWithInt:1],
(NSString *)kCFStreamPropertyHTTPSProxyHost : proxyHost,
(NSString *)kCFStreamPropertyHTTPSProxyPort : proxyPort,
};
NSMutableURLRequest *req = [correctedRequest mutableCopy];
/
NSString *proxyUsername = @"abcd";
NSString *proxypassword = @"abcd123";
NSString *authenticationString = [NSString stringWithFormat:@"%@:%@", proxyUsername, proxypassword];
NSData *authenticationData = [authenticationString dataUsingEncoding:NSASCIIStringEncoding];
NSString *authenticationValue = [authenticationData base64Encoding];
authenticationValue = [@"Basic " stringByAppendingString:authenticationValue];
[req setValue:authenticationValue forHTTPHeaderField:@"Proxy-Authorization"];
correctedRequest = [req copy];
NSURLSessionConfiguration *configuration1 = [NSURLSessionConfiguration ephemeralSessionConfiguration];
configuration1.connectionProxyDictionary = proxyDict;
/------------END ATTACHING PROXY TO THE REQUEST-----------*/
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration1 delegate:self delegateQueue:nil];
NSURLSessionDataTask * dataTask = [session dataTaskWithRequest:correctedRequest];
[dataTask resume];
}
The above code works for some URL's/websited without asking the user to enter the proxy credentials manually but the same code doesnt work for some websites and a pop appears asking the user to enter the authentication credentials manually. What is the reason for such a behaviour? Do I need to make any changes in my code to get this fixed?
Thanks in advance!!