NSURLConnection中的代理HTTP

时间:2016-02-12 02:31:49

标签: xcode proxy nsurlconnection nsurlsessionconfiguration

我试图通过使用下面的代码在NSURLConnection中代理我的请求,我的问题是,当我应该返回的是一个IP地址来显示时,我从一个似乎是代理的东西得到一个奇怪的响应代理正在运作。我的NSURLResponse很好,所以我不确定这里到底发生了什么。任何帮助非常感谢,谢谢!

SELECT poolmonth,
       origination,
       [201512],
       [201512]+[201601] as [201601],
       [201512]+[201601]+[201602] as [201602]
  FROM (SELECT poolmonth, 
               SUM(OriginationAmt) origination,
               SUM(CASE WHEN PmtDue = 201512
                        THEN amtpaid ELSE 0 END) as [201512],
               SUM(CASE WHEN PmtDue = 201601
                        THEN amtpaid ELSE 0 END) as [201601],
               SUM(CASE WHEN PmtDue = 201602
                        THEN amtpaid ELSE 0 END) as [201602]
          FROM Loans
         GROUP BY poolmonth
       ) newloans

\\这是我回来的时候我应该回到代理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]);
                              }];

0 个答案:

没有答案