首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSURLSessionConfiguration未返回URLRequest数据

NSURLSessionConfiguration未返回URLRequest数据
EN

Stack Overflow用户
提问于 2016-10-08 16:46:28
回答 1查看 101关注 0票数 0

我正在使用以下代码在URLConfiguration中设置代理设置。

代码语言:javascript
复制
NSString *proxyHost = @"192.168.xx.xxx";
NSNumber *proxyPort = [NSNumber numberWithInteger:8090];
NSString *request = [NSString stringWithFormat:
                     @"http://example.com/sampleid?id=506"];

NSURL *URL = [NSURL URLWithString:
              [request stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];


NSURL *url = [NSURL URLWithString:[request stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSURLRequest *URLrequest = [NSURLRequest requestWithURL:url];

NSDictionary *proxyDict = @{
                            @"HTTPEnable"  : [NSNumber numberWithInt:1],
                            (NSString *)kCFStreamPropertyHTTPProxyHost  : proxyHost,
                            (NSString *)kCFStreamPropertyHTTPProxyPort  : proxyPort,
                            (NSString *)kCFProxyUsernameKey : hostUserName,
                            (NSString *)kCFProxyPasswordKey : hostPassword,

                            @"HTTPSEnable" : [NSNumber numberWithInt:1],
                            (NSString *)kCFStreamPropertyHTTPSProxyHost : proxyHost,
                            (NSString *)kCFStreamPropertyHTTPSProxyPort : proxyPort,
                            (NSString *)kCFProxyUsernameKey : hostUserName,
                            (NSString *)kCFProxyPasswordKey : hostPassword,
                            };

NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
sessionConfig.connectionProxyDictionary = proxyDict;

NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: sessionConfig delegate: nil delegateQueue: [NSOperationQueue mainQueue]];

__block NSDictionary *returnJsonDictionary;
__block NSError *error1;

NSURLSessionDataTask *task = [defaultSession dataTaskWithRequest:URLrequest completionHandler:
                              ^(NSData *data, NSURLResponse *response, NSError *error) {
                                  NSLog(@"NSURLSession got the response [%@]", response);
                                  NSLog(@"NSURLSession got the data [%@]", data);
}];
[task resume];

但是下面这行代码^(NSData *data, NSURLResponse *response, NSError *error)返回我的proxyHost的结果,而不是返回URL(http://example.com/sampleid?id=506)的数据。

有人能帮我解决这个问题吗?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-10-11 23:27:46

代码语言:javascript
复制
sessionConfig.connectionProxyDictionary = proxyDict;

试着把它注释掉,看看它是否能解决你的问题。从你对我的更改的回应,在我的帖子上的代理评论,似乎你实际上并不想通过代理进行连接。还有,什么是

proxyHost

proxyPort

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39930453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档