2015-05-06 60 views
1

我正在使用AFNetworking將視頻和圖像上載到服務器。AFNetworking中的響應頭和URL

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 =  (
    ); 
} 

我已經爲此搜了很多,但找不到任何有用的東西。這個你能幫我嗎。

+0

http://stackoverflow.com/questions/ 19114623/request-failed-unacceptable-content-type-text-html-using-afnetworking-2-0請檢查可能會對你有幫助 – Harish

回答

1

你與真實的反應記錄頭:

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

您所期望的響應只是responseObject顯然是一本字典。

NSLog(@"%@", responseObject);

例如,您可以訪問 「消息」 這樣做的:

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

應登錄: 「測試按鈕」

+0

非常感謝很多人,我只是很專心看不到那個來 – channi