Proxy HTTP in NSURLConnection

560 Views Asked by At

I am trying to proxy my requests in a NSURLConnection by using the code below, My problem is that I am getting a strange response from what seems to be the proxy when all I should be getting back is a IP address to show that the proxy is working. My NSURLResponse is fine so i am not sure what is really going on here. Any help much appreciated, Thanks!

NSString* proxyHost = @"http://180.177.**.***";
NSNumber* proxyPort = [NSNumber numberWithInt:80];


NSDictionary *proxyDict = @{
                            @"HTTPEnable"  : [NSNumber numberWithInt:1],
                            (NSString *)kCFStreamPropertyHTTPProxyHost  : proxyHost,
                            (NSString *)kCFStreamPropertyHTTPProxyPort  : proxyPort,
                            (NSString *)kCFProxyTypeKey : (NSString *)kCFProxyTypeHTTP,
                            };


NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];  
configuration.connectionProxyDictionary = proxyDict;

NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:[[NSOperationQueue alloc] init]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://myexternalip.com/raw"]];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:
                              ^(NSData *data, NSURLResponse *response, NSError *error) {
                                  NSLog(@"%@",error);
                                  NSLog(@"NSURLSession got the response [%@]", response);
                                  NSLog(@"NSURLSession got the data [%@]", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
                              }];

\\ This is what I am getting back when i should just be getting back the proxy IP

  <html><head><meta http-equiv="refresh"      content="0;url=http://www.dnsrsearch.com/index.php?     origURL=http://myexternalip.com/raw&bc="/></head><body><script      type="text/javascript">window.location="http://www.dnsrsearch.com/index.p     hp?     origURL="+escape(window.location)+"&r="+escape(document.referrer)+"&bc=";     </script></body></html>

 ///And this is my NSURLResponse///
  { URL: http://myexternalip.com/raw } { status code: 200, headers {
"Cache-Control" = "no-cache";
Connection = close;
"Content-Encoding" = gzip;
"Content-Type" = "text/html";
Date = "Fri, 12 Feb 2016 02:20:34 GMT";
Expires = "Fri, 12 Feb 2016 02:20:33 GMT";
Server = nginx;
"Transfer-Encoding" = Identity;
Vary = "Accept-Encoding";
 } }
0

There are 0 best solutions below