gpt4 book ai didi

iphone - 调试 AFNetworking

转载 作者:可可西里 更新时间:2023-11-01 16:50:34 25 4
gpt4 key购买 nike

以下代码块用于将图像文件提交到数据库。它已停止工作:尽管它打印了 SUCCESS,但服务器上没有任何图像可见。关于如何调试它有什么建议吗?

编辑

我在调试器中打印了 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];
}

最佳答案

调试 HTTP 连接时我的首选工具是 Charles .您可以在台式计算机上设置 Charles,在 iPhone 上将其配置为代理,然后观察 iPhone 产生的 HTTP 流量。然后,您可以查看是否正在发出请求,如果是,则深入检查每个请求。

以下是设置 Charles 以查看 iPhone HTTP 流量的一些很好的说明:http://blog.mediarain.com/2009/08/iphone-http-connection-debugging/

关于iphone - 调试 AFNetworking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10852029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com