0

以下のコードを使用して、NSURLConnection でリクエストをプロキシしようとしています。私の問題は、プロキシが働く。私の 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