我正在我的项目中使用AFNetworking,我只需要检查一个网址是否成功(状态为2xx)。
我试过了
NSURLRequest *request = [NSURLRequest requestWithURL:url2check];
AFJSONRequestOperation *operation = [AFJSONRequestOperation
JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
if (response.status == 200) {
NSLog(@"Ok %@", JSON);
}
}
failure:nil
];
[operation start];但是由于我没有特别等待JSON,所以我希望使用类似这样的东西
AFHTTPRequestOperation *operation = [AFHTTPRequestOperation
HTTPRequestOperationWithRequest: success: failure:];但这并不存在(我不知道为什么),所以我使用了
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]
initWithRequest:request];
[operation setCompletionBlockWithSuccess:...]有没有更简单的?
你怎么用AFNetworking做这个简单的网址检查呢?
发布于 2013-04-23 22:17:58
您只需使用基URL实例化一个AFHTTPClient对象并对其调用getPath:parameters:success:failure:即可。
from the docs:
创建一个带有GET请求的AFHTTPRequestOperation,并将其加入到客户端的操作队列中。
https://stackoverflow.com/questions/16170487
复制相似问题