Eri*_*tto 1 iphone xcode http objective-c afnetworking
以下代码块用于将图像文件提交到数据库.它已停止工作:即使打印SUCCESS
,服务器上也看不到任何图像.关于如何调试这个的任何建议?
EDITS
我在调试器中打印了imageData并得到了一个内存地址数组,所以我几乎可以肯定我有一个图像.
- (void)postActivityImage:(Spot*)localSpot
{
NSLog(@"%s",__func__);
NSString *url = [NSString stringWithFormat:@"v1/activity/%@/image", localSpot.uniqueID];
UIImage *image = [UIImage imageWithContentsOfFile:localSpot.imageLocalURL];
NSData *imageData = UIImageJPEGRepresentation(image, 0.5f);
NSURLRequest *request = [httpClient_ multipartFormRequestWithMethod:@"POST"
path:url
parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageData
name:@"test"
fileName:@"test"
mimeType:@"image/jpeg"];
}];
AFJSONRequestOperation *ro;
ro = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSURLResponse *response, id JSON) {
NSLog(@"success: %@", JSON);
NSLog(@"SUCCESS - IMAGE POSTED.");
[self updateSpotSubmitInProgressStatusWithActivityFinished:ImagePost andSuccess:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:SUBMIT_STATUS object:self userInfo:nil];
self.spot.imageSubmitted = YES;
} failure:^(NSURLRequest *request, NSURLResponse *response, NSError *error, id JSON) {
[self updateSpotSubmitInProgressStatusWithActivityFinished:ImagePost andSuccess:NO];
NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:error, @"Error", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:SUBMIT_STATUS object:self userInfo:dic];
NSLog(@"%s ERROR: %@", __func__, error);
NSLog(@"%s RESPONSE: %@",__func__, response);
NSLog(@"%s FAIL json response: %@",__func__, JSON);
}];
[httpClient_ enqueueHTTPRequestOperation:ro];
}
Run Code Online (Sandbox Code Playgroud)
调试HTTP连接时,我的首选工具是Charles.您可以在桌面计算机上设置Charles,将其配置为iPhone上的代理,然后观察iPhone生成的HTTP流量.然后,您可以查看是否正在进行请求,如果是,则深入检查每个请求.
以下是设置Charles查看iPhone HTTP流量的一些很好的说明:http://blog.mediarain.com/2009/08/iphone-http-connection-debugging/
归档时间: |
|
查看次数: |
1757 次 |
最近记录: |