我要把图片换成nsdata,然后再用base64encoding,把encoding后生成的字符串上传到
服务器,就出这个问题,
报错信息:err:Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed:
请求太大 (413)"
我同事用的ASIHTTPRequest库就没问题,请问如何解决?
代码:
UIImage *img = [self createThumbnailWithSourceImge:sourceImg andNewSize:sz];
data = UIImageJPEGRepresentation(img, 0.01);
NSString *encodedSTR = [data base64Encoding];
NSString *currentUrl = @"/app/b/test";
NSString *urlStr = [NSString stringWithFormat:@"%@%@?picStr=%@",BASEURL,currentUrl,encodedSTR];
NSURL *url = [NSURL URLWithString:urlStr];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc]initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// NSLog(@"success:%@",responseObject);
successBlock(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failureBlock(error);
}];
[op start];
// [manager POST:urlStr parameters:nil
// success:^(AFHTTPRequestOperation *operation, id responseObject) {
// NSLog(@"success:%@",responseObject);
// } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// NSLog(@"err:%@",error);
// }];
使用AFNetworking 2.0 请求数据时出现错误 Request failed: unacceptable content-type: text/html 解决方法
添加一行manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
即可
整个代码为:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
NSDictionary *parameters = @{@"foo":@"bar"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@",responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error:%@",error);
}];
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。