我要把图片换成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];
添加回答
举报
0/150
提交
取消