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;
}