我基本上是在尝试下载一个可以从 PDF 到 PNG 的文件。我正在使用 AFNetworking 1.x。
但是,我收到一个错误:
NSURL *baseURL = [NSURL URLWithString:@"https://myserver.com/webservices/Services/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
//NSLog(@"Formatted URL: %@", formattedURL);
//NSMutableURLRequest *photoRequest = [NSMutableURLRequest requestWithURL:url];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[httpClient defaultValueForHeader:@"Accept"];
[httpClient setParameterEncoding:AFFormURLParameterEncoding];
[parameters setObject:[NSNumber numberWithInteger:@"10772"] forKey:@"FileId"];
[parameters setObject:[NSNumber numberWithBool:YES] forKey:@"requireUnCompression"];
NSMutableURLRequest *fileRequest = [httpClient requestWithMethod:@"POST" path:@"FileService.svc/DownloadFile" parameters:parameters];
//[fileRequest setHTTPBody:<#(NSData *)#>]
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:fileRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successss!");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failed: %@", [operation error]);
}];
[httpClient enqueueHTTPRequestOperation:operation];
但是,我收到一个错误:
Failed: Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x12112770 {NSLocalizedRecoverySuggestion={"faultType":"InvalidOperationException","message":"The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details."}, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0xc865c40> { URL: https://myserver.com/webservice/Services/FileService.svc/DownloadFile }, NSErrorFailingURLKey=https://myserver.com/webservices/Services/FileService.svc/DownloadFile, NSLocalizedDescription=Expected status code in (200-299), got 400, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xc8696a0> { URL: https://myserver.com/webservices/Services/FileService.svc/DownloadFile } { status code: 400, headers {
"Cache-Control" = private;
"Content-Length" = 327;
"Content-Type" = "application/xml; charset=utf-8";
Date = "Thu, 17 Oct 2013 19:45:07 GMT";
"Persistent-Auth" = true;
Server = "Microsoft-IIS/8.0";
"X-AspNet-Version" = "4.0.30319";
"X-Powered-By" = "ASP.NET";
} }}
先感谢您!