AFNetworking 中的响应 Headers 和 URL

Response Headers and URL in AFNetworking

我正在使用 AFNetworking 将视频和图像上传到服务器。

NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:urlString parameters:dictParams constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imgData name:@"photo" fileName:@"photo.jpg" mimeType:@"image/jpeg"];
[formData appendPartWithFileData:[NSData dataWithContentsOfFile:pathVideo] name:@"video" fileName:@"video.mp4" mimeType:@"video/mp4"];
    } error:nil];

AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSProgress *progress = nil;

NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
    if (error) {
        NSLog(@"Error: %@", error);
    } else {
        NSLog(@"%@ %@", response, responseObject);
    }
}];

[uploadTask resume];

但在响应中我得到响应 Headers 和 URL 以及所需的响应。

{ URL: the_url.com } { status code: 200, headers {
    Connection = "Keep-Alive";
    "Content-Length" = 49;
    "Content-Type" = "text/html; charset=UTF-8";
    Date = "Wed, 06 May 2015 11:12:50 GMT";
    "Keep-Alive" = "timeout=5, max=100";
    Server = "Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.6.7";
    "X-Powered-By" = "PHP/5.6.7";
} } {
    error = 0;
    message = "Test Button";
    response =     (
    );
}

我为此搜索了很多,但找不到任何有用的信息。请帮我解决这个问题。

您正在使用真实响应记录 header:

NSLog(@"%@ %@", response, responseObject);

您想要的响应只是 responseObject 显然是一个字典。

NSLog(@"%@", responseObject);

例如,您可以访问 "message" 做:

NSLog(@"%@", responseObject[@"message"]);

应该记录:"Test Button"