如何获得 JSON 响应?如果 PHP 打印一些 JSON 整个请求失败,如果 PHP 不打印任何内容,则响应成功。如何使用 AFHTTPRequestOperation ?
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"foo":@"barr"};
UIImage *image = myImage.image;
[manager POST:@"http://local/index.php"
parameters:parameters
constructingBodyWithBlock:^(id<AFMultipartFormData> formData){
[formData appendPartWithFileData:UIImageJPEGRepresentation(image, 0.7)
name:@"file"
fileName:@"photo.jpg"
mimeType:@"image/jpeg"];
}
success:^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"Success: %@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"Error %@", operation.responseString);
}];