用 oc 发 http get 无任何反应,求解

2016-03-03 11:38:55 +08:00
 wohenyingyu01
方法:

main 函数里:


执行后,断点不进去,结果是
the result from ipip is (null)
1339 次点击
所在节点    问与答
2 条回复
wohenyingyu01
2016-03-03 11:39:58 +08:00
这图= =
我把代码复制一遍好了


+(NSString *)requestHTTPGetFromURL:(NSString *)url{
NSString* __block result;
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];

NSURL * target = [NSURL URLWithString:url];

NSURLSessionDataTask * dataTask = [defaultSession dataTaskWithURL:target
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if(error == nil)
{
result = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"Data = %@",result);
}else{
NSLog(@"The error is :%ld",[error code]);
}

}];

[dataTask resume];

return result;
}
xi_lin
2016-03-03 13:19:41 +08:00
实验了一下没有问题
Data = ["GOOGLE","GOOGLE","","","google.com"]

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/260745

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX