这是我上传文件的 POST 请求。如何在实际发送之前对发送到服务器的 JSON 进行 NSLog 记录?
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:twitid forKey:@"twit"];
[dict setObject:hash forKey:@"hash"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
if ([mediaFile isKindOfClass:[UIImage class]])
{
imageData = UIImageJPEGRepresentation(mediaFile, 0.5);
}
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:nil parameters:dict constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
if ([mediaFile isKindOfClass:[UIImage class]])
{
[formData appendPartWithFileData:imageData name:@"media" fileName:@"picture.png" mimeType:@"image/png"];
}
else if(isThisAudio)
{
[formData appendPartWithFileData:mediaFile name:@"media" fileName:@"audio.caf" mimeType:@"audio/caf"];
}
else
{
[formData appendPartWithFileData:mediaFile name:@"media" fileName:@"movie.mov" mimeType:@"video/quicktime"];
}
}];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
NSDictionary *jsonDictionary = JSON;
NSLog(@"jsonDictionary: %@",jsonDictionary);
}
failure:^(NSURLRequest *request , NSURLResponse *response , NSError *error , id JSON)
{
NSLog(@"Failed: %@",[error localizedDescription]);
}];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
percentDone = ((float)((int)totalBytesWritten) / (float)((int)totalBytesExpectedToWrite));
NSLog(@"Uploaded %f",percentDone);
}];
[httpClient enqueueHTTPRequestOperation:operation];