Xcode NSURLConnection中的代理HTTP

Xcode NSURLConnection中的代理HTTP,xcode,proxy,nsurlconnection,nsurlsessionconfiguration,Xcode,Proxy,Nsurlconnection,Nsurlsessionconfiguration,我正试图使用下面的代码在NSURLConnection中代理我的请求,我的问题是,当我应该返回的只是一个IP地址以显示代理正在工作时,我从似乎是代理的位置收到一个奇怪的响应。我的回答很好,所以我不确定这里到底发生了什么。非常感谢您的帮助,谢谢 NSString* proxyHost = @"http://180.177.**.***"; NSNumber* proxyPort = [NSNumber numberWithInt:80]; NSDictionary *proxyDict = @

我正试图使用下面的代码在NSURLConnection中代理我的请求,我的问题是,当我应该返回的只是一个IP地址以显示代理正在工作时,我从似乎是代理的位置收到一个奇怪的响应。我的回答很好,所以我不确定这里到底发生了什么。非常感谢您的帮助,谢谢

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";
 } }
window.location=”http://www.dnsrsearch.com/index.p     hp?origURL=“+escape(window.location)+”&r=“+escape(document.referer)+”&bc=“;
///这是我的回答///
{URL:http://myexternalip.com/raw }{状态代码:200,标题{
“缓存控制”=“无缓存”;
连接=关闭;
“内容编码”=gzip;
“内容类型”=“文本/html”;
日期=“2016年2月12日星期五02:20:34 GMT”;
Expires=“2016年2月12日星期五02:20:33 GMT”;
服务器=nginx;
“传输编码”=标识;
Vary=“接受编码”;
} }

这似乎是我使用的代理,现在我从服务器得到了正确的响应。如果有人能给我提供更多的信息,我还是很想知道,谢谢。我也收到了同样的问题。你解决这个问题了吗?如果是的话,请帮助我。请详细说明您的答案/评论使用不同的代理我不明白,不同的代理方式?请更改您试图连接到端点服务器的代理。例如,我使用@“.**.**”作为我的代理。我将其更改为另一个正在使用的IP。