响应标题和Afnetworking中的URL



我正在使用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];

但是,在响应中,我得到了响应标题和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 =     (
    );
}

我为此搜索了很多东西,但找不到任何有用的东西。请帮助我。

您正在用真实响应记录标头:

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

您所需的响应只是响应观点显然是字典。

NSLog(@"%@", responseObject);

例如,您可以访问"消息"执行:

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

应该记录:"测试按钮"

最新更新