AFNetworkingErrorDomain 错误
AFNetworking
and POST Request
I'm getting this response in error.userInfo while making a POST request from AFNetworking
.
Can anyone tell either I'm missing anything obvious or something need to fix at my server end?
Request Failed with Error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {( "text/json", "application/json", "text/javascript" )}, got text/html" UserInfo=0x6d7a730 {NSLocalizedRecoverySuggestion=index test, AFNetworkingOperationFailingURLResponseErrorKey=,
NSErrorFailingURLKey=http://54.245.14.201/, NSLocalizedDescription=Expected content type {( "text/json", "application/json", "text/javascript" )}, got text/html, AFNetworkingOperationFailingURLRequestErrorKey=http://54.245.14.201/>}, { AFNetworkingOperationFailingURLRequestErrorKey
= "http://54.245.14.201/>"; AFNetworkingOperationFailingURLResponseErrorKey = ""; NSErrorFailingURLKey = "http://54.245.14.201/"; NSLocalizedDescription = "Expected content type {(\n \"text/json\",\n \"application/json\",\n
\"text/javascript\"\n)}, got text/html"; NSLocalizedRecoverySuggestion = "index test"; }
And I'm using this code;
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient setDefaultHeader:@"Accept" value:@"application/json"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"Ans", @"name",
@"29", @"age",
nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"/" parameters:params];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Success");
NSLog(@"%@",JSON);
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
NSLog(@"Failure");
}];
[operation start];
[operation waitUntilFinished];
By default, AFJSONRequestOperation
accepts
only "text/json", "application/json" or "text/javascript" content-types from server, but you are getting "text/html".
Fixing on server would be better, but you can also add "text/html" content type as acceptable in your app:
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];
版权声明:本文为博主原创文章,未经博主允许不得转载。
最新文章
- Python对时间的转换
- Spring学习笔记(一)
- AngularJS快速入门指南17:Includes
- Access restriction: The type 'BASE64Encoder' is not API
- LoadRunner常用函数列表
- Swift中的Masonry第三方库——SnapKit
- php 面向对象之封装
- PMP项目管理笔记 项目定义
- mysql 找不到或无法加载已注册的 .Net Framework Data Provider
- OpenGL9-(FreeImage)加载图片-作为纹理
- 【HDOJ】1175 连连看
- Android的多媒体框架OpenCore介绍
- php+apache+mysql的安装
- sublime text3在指定浏览器上本地服务器(localhost)运行文件(php)
- js 移动端上拉加载下一页通用方案
- Kotlin从入门到放弃
- [NIO-2]通道和FileChannel
- 大数据实践:ODI 和 Twitter (二)
- 让div获取焦点
- Entity Framework学习初级篇3--LINQ TO Entities
热门文章
- js对象类型判断工具
- SQL Sever实验一 创建和删除数据库数据表
- PhpSpreadsheet处理表格2
- System.getProperty()和getenv()
- python通过http(multipart/form-data)上传文件的方法
- IO流1 --- File类的实例化 --- 技术搬运工(尚硅谷)
- java获取外网ip地址
- SDUT-3400_数据结构实验之排序三:bucket sort
- 洛谷P1541 乌龟棋 [2010NOIP提高组]
- 【水滴石穿】react-native-ble-demo