提问人:user1887842 提问时间:2/23/2022 最后编辑:user1887842 更新时间:2/23/2022 访问量:76
AFNetworking 上传 PDF 文件
AFNetworking upload PDF file
问:
我正在尝试使用 AFNetworking 3.0 将 pdf 文件上传到服务器,
我的 pdf 文件以 NSData 的形式发送 但它返回了我这个错误:
NSError * domain: @"com.alamofire.error.serialization.response" - code: 18446744073709550605
我的代码:
-(void)uploadPDFFile{
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"URLREQUEST" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:self->originalDataPDF name:@"fileName" fileName:self->fileNamePDF mimeType:@"application/pdf"];
}
error:nil];
AFURLSessionManager *manager = [[AFURLSessionManager alloc]
initWithSessionConfiguration:[NSURLSessionConfiguration
defaultSessionConfiguration]];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSURLSessionUploadTask *uploadTask;
uploadTask = [manager uploadTaskWithStreamedRequest:request
progress:^(NSProgress * _Nonnull uploadProgress) {
// This is not called back on the main queue.
// You are responsible for dispatching to the main queue for UI updates
}
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"%@",[[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding]);
} else {
NSLog(@"WORKING ");
}
}];
[uploadTask resume];
}
打印responseObject时,错误日志返回我:
406 不可接受不 可以接受
所请求的适当表示 在此服务器上找不到资源。
此外,406 尝试使用 ErrorDocument 来处理请求。
感谢您的帮助
答: 暂无答案
评论
manager.responseSerializer = [AFHTTPResponseSerializer serializer]
responseObject
responseObject
NSData
[[NSString alloc]] initWithData: responseObject encoding: NSUTF8StringEncoding]