关于使用AFNetWorking 上传字符串,请求失败,Request failed: 请求太大 -问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

关于使用AFNetWorking 上传字符串,请求失败,Request failed: 请求太大

我要把图片换成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);
         //     }];

展开
收起
爵霸 2016-03-13 09:44:21 2772 0
1 条回答
写回答
取消 提交回答
  • 爵霸

    使用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);
     }];
    2019-07-17 19:01:50
    赞同 展开评论 打赏
问答排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载