为了账号安全,请及时绑定邮箱和手机立即绑定

使用AFNetWorking 上传字符串,提示:Request failed: 请求太大

使用AFNetWorking 上传字符串,提示:Request failed: 请求太大

米琪卡哇伊 2019-04-14 10:35:07
我要把图片换成nsdata,然后再用base64encoding,把encoding后生成的字符串上传到服务器,就出这个问题,报错信息:err:ErrorDomain=com.alamofire.error.serialization.responseCode=-1011"Requestfailed:请求太大(413)"我同事用的ASIHTTPRequest库就没问题,请问如何解决?代码:UIImage*img=[selfcreateThumbnailWithSourceImge:sourceImgandNewSize:sz];data=UIImageJPEGRepresentation(img,0.01);NSString*encodedSTR=[database64Encoding];NSString*currentUrl=@"/app/b/test";NSString*urlStr=[NSStringstringWithFormat:@"%@%@?picStr=%@",BASEURL,currentUrl,encodedSTR];NSURL*url=[NSURLURLWithString:urlStr];NSURLRequest*request=[NSURLRequestrequestWithURL:url];AFHTTPRequestOperation*op=[[AFHTTPRequestOperationalloc]initWithRequest:request];op.responseSerializer=[AFJSONResponseSerializerserializer];[opsetCompletionBlockWithSuccess:^(AFHTTPRequestOperation*operation,idresponseObject){//NSLog(@"success:%@",responseObject);successBlock(responseObject);}failure:^(AFHTTPRequestOperation*operation,NSError*error){failureBlock(error);}];[opstart];//[managerPOST:urlStrparameters:nil//success:^(AFHTTPRequestOperation*operation,idresponseObject){//NSLog(@"success:%@",responseObject);//}failure:^(AFHTTPRequestOperation*operation,NSError*error){//NSLog(@"err:%@",error);//}];
查看完整描述

2 回答

?
守候你守候我

TA贡献1802条经验 获得超10个赞

图片转换成NSData之后就不用再转String了,直接上传就行了。
AFHTTPRequestOperationManager*manager=[[AFHTTPRequestOperationManageralloc]initWithBaseURL:[NSURLURLWithString:BASEURL]];
NSData*imageData=UIImageJPEGRepresentation(img,0.1);
NSDictionary*parameters=@{@"你们需要的参数":XXXXXXX};
AFHTTPRequestOperation*op=[managerPOST:currentUrlparameters:parametersconstructingBodyWithBlock:^(idformData){
[formDataappendPartWithFileData:imageDataname:paramNameForImagefileName:@"photo.jpg"mimeType:@"image/jpeg"];
}success:^(AFHTTPRequestOperation*operation,idresponseObject){
NSLog(@"Success:%@*****%@",operation.responseString,responseObject);
}failure:^(AFHTTPRequestOperation*operation,NSError*error){
NSLog(@"Error:%@*****%@",operation.responseString,error);
}];
[opstart];
                            
查看完整回答
反对 回复 2019-04-14
  • 2 回答
  • 0 关注
  • 371 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信