0

我正在尝试使用下面的代码在 NSURLConnection 中代理我的请求,我的问题是我从似乎是代理的地方得到了一个奇怪的响应,而我应该得到的只是一个 IP 地址来表明代理是在职的。我的 NSURLResponse 很好,所以我不确定这里到底发生了什么。非常感谢任何帮助,谢谢!

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]);
                              }];

\\ 这就是当我应该取回代理 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";
 } }
4

0 回答 0