iOS- "unacceptable content-type: text/plain"等content-type bug解决方案

时间:2023-02-15 19:56:54

经常在使用AFN的时候会出现content-type错误,缺少请求类型,比如”unacceptable content-type: text/plain”
iOS- "unacceptable content-type: text/plain"等content-type bug解决方案

解决方法:
1.在网络请求代码处修改

AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
mgr.responseSerializer = [AFHTTPResponseSerializer serializer];

2.直接修改AFN源文件

1)找到AFN设定Content-type的地方
复制用-> AFURLResponseSerialization.m

iOS- "unacceptable content-type: text/plain"等content-type bug解决方案

self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",nil];

修改为:

self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/plain" ,nil];

缺少什么类型的content-type ,增加相应的.