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

我要把图片换成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);
//}];
米琪卡哇伊
浏览 372回答 2
2回答

守候你守候我

图片转换成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];
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript