[英]AFNetworking not getting proper response
我正在嘗試使用AFNetworking調用Rest API,但沒有得到正確的響應字符串。 這是我的代碼:
NSURL *url = [[NSURL alloc] initWithString:@"https://www.ez-point.com/api/v1/ezpoints"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"%@",@"testing");
NSLog(@"%@",operation.responseData);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"%@", @"Error");
}];
[operation start];
但是我正在打印出來:
2013-10-29 08:31:08.175 EZ-POINT[4004:c07] testing
2013-10-29 08:31:08.175 EZ-POINT[4004:c07] (null)
如您所見,它返回null,我期望這樣:
{"status": "user_invalid", "data": "", "token": "", "errors": ["user not found"], "user_id": ""}
我更習慣這種設置請求的方式:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.ez-point.com/api/v1/ezpoints"]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"%@",@"testing");
NSLog(@"%@",operation.responseData);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"%@", @"Error");
}];
[operation start];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.