博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AFNetwirking的post请求返回错误!如代码 ?
阅读量:5865 次
发布时间:2019-06-19

本文共 1891 字,大约阅读时间需要 6 分钟。

hot3.png

   AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager];
//    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject: @"text/plain"];
    [manager POST:@"http://wu.itmingong.org:9090/WuNetbars/app/login.do"parameters:parameters success:^(AFHTTPRequestOperation *operation,idresponseObject) {
//        NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"success");
    } failure:^(AFHTTPRequestOperation *operation,NSError*error) {
        NSLog(@"错误,%@", error);
    }];
错误信息
Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo=0x7fbf4947edf0 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fbf49484230> { URL:
 } { status code: 400, headers {
    Connection = close;
    "Content-Language" = en;
    "Content-Length" = 1011;
    "Content-Type" = "text/html;charset=utf-8";
    Date = "Wed, 21 Jan 2015 05:34:22 GMT";
    Server = "Apache-Coyote/1.1";
    "Set-Cookie" = "JSESSIONID=B2726D9C845F31BE9A68D06845E52080; Path=/WuNetbars/; HttpOnly";
} },
框架里面
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain", @"text/html", nil]; 我都有啊

是请求头的问题么?求大神指点 

终于搞好了,原因是我用加密过的字符串,其中有加减等特殊符号,AFN框架直接处理字符串时会改变这些特殊符号和加些字符串,所以修改AFN内部这一部分即可 

  NSString *query = nil;

        if (self.queryStringSerialization) {
            NSError *serializationError;
            query = self.queryStringSerialization(request, parameters, &serializationError);
            if (serializationError) {
                if (error) {
                    *error = serializationError;
                }
                return nil;
            }
            query = (NSString *)parameters;
添加最后一句就好了,前面是AFN判断修改的 

转载于:https://my.oschina.net/u/1244672/blog/540393

你可能感兴趣的文章
字符编码
查看>>
KVM基本概念
查看>>
Android 学习:Manifest 文件--Android Manifest.xml
查看>>
小程序开发与网页开发的区别
查看>>
第一章首次运行 IntelliJ IDEA 示例
查看>>
Chrome下Failed to load resource问题居然是由于AdBlock
查看>>
C语言复制数组
查看>>
hdu 1211 RSA (逆元)
查看>>
HLG 1028 Repeater【图形处理】
查看>>
python 学习地址
查看>>
Mongodb高级篇-性能优化
查看>>
mysql数据库优化总结(心得)
查看>>
移动端链接、点击事件、输入框去除背景高亮
查看>>
CF1106E Lunar New Year and Red Envelopes
查看>>
二分答案—洛谷P1182 数列分段`Section II`
查看>>
Luogu P2619 [国家集训队2]Tree I 凸优化,wqs二分
查看>>
搭个小窝
查看>>
Socket编程 --- TCP
查看>>
15款新鲜出炉的实用网页设计工具
查看>>
java 获取本机ip
查看>>