利用AFNetworking3.0 POST 上传问题:求大神解释

Mr_TIG 2016-06-01 04:08:32
- (void)uploadDocumentWithImageData:(NSData *)data withType:(NSString *)type{
AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
sessionManager.requestSerializer = [AFHTTPRequestSerializer serializer];
sessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil];

NSString *postUrl = [[uploadDocumentString stringByAppendingString:[NSString stringWithFormat:@"&userName=%@&password=%@",self.defaultManager.userInfo[0],self.defaultManager.userInfo[1]]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSLog(@"url ==== %@",postUrl);
__block NetWorker *selfNetW = self;
[sessionManager POST:postUrl parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
dateFormatter.dateFormat = @"yyyyMMddHHmmss";

NSString *dateStr = [dateFormatter stringFromDate:[NSDate date]];

NSMutableString *userName =[NSMutableString stringWithString:selfNetW.defaultManager.userInfo[0]];
NSString *fileNameString = [NSString stringWithFormat:@"%@-%@-%@.jpg",userName,type,dateStr];

[formData appendPartWithFileData:data name:type fileName:fileNameString mimeType:@"image/jpeg"];

} progress:^(NSProgress * _Nonnull uploadProgress) {
NSLog(@"progress == %2f",uploadProgress.completedUnitCount *1.0/data.length);
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {

NSLog(@"上传成功==%@",responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"上传失败==%@",error);
}];


}


错误信息:
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: not found (404)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x78a1a770> { URL: http://oter.com/mpApi/uploadDocument?merCode=882888&merKey=GDgLwwdK270Qj1w4xhiy3DQ&userName=DEMO123&password=demo123 } { status code: 404, headers {
"Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
Connection = close;
"Content-Length" = 2268;
"Content-Type" = "text/html; charset=utf-8";
Date = "Wed, 01 Jun 2016 07:44:55 GMT";
Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
Pragma = "no-cache";
Server = Apache;
Status = "404 Not Found";
"X-Powered-By" = "PHP/5.4.38";
} }, NSErrorFailingURLKey=http://oter.com/mpApi/uploadDocument?merCode=882888&merKey=GDgLwwdK270Qj1w4xho8lyTpRQZV9Jm5x4NwWOTThUa4fMhEBK9jOXOMcNv8rncRiy3DQ&userName=DEMO123&password=demo123, NSLocalizedDescription=Request failed: not found (404), com.alamofire.serialization.response.error.data=<3c21444f 43545950 45206874 6d6c2050 55424c49 4320222d 2f2f5733 432f2f44 54442058 48544d4c 20312e30 20547261...
...全文
333 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mr_TIG 2016-06-01
  • 打赏
  • 举报
回复
首先谢谢你的回答,其次检查下什么路径?你所说的路径是什么意思啊?
不担心 2016-06-01
  • 打赏
  • 举报
回复
404错误 服务器端的页面找不到,检查一下路径

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧