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"]];

版权声明:本文为博主原创文章,未经博主允许不得转载。

最新文章

  1. Python对时间的转换
  2. Spring学习笔记(一)
  3. AngularJS快速入门指南17:Includes
  4. Access restriction: The type 'BASE64Encoder' is not API
  5. LoadRunner常用函数列表
  6. Swift中的Masonry第三方库——SnapKit
  7. php 面向对象之封装
  8. PMP项目管理笔记 项目定义
  9. mysql 找不到或无法加载已注册的 .Net Framework Data Provider
  10. OpenGL9-(FreeImage)加载图片-作为纹理
  11. 【HDOJ】1175 连连看
  12. Android的多媒体框架OpenCore介绍
  13. php+apache+mysql的安装
  14. sublime text3在指定浏览器上本地服务器(localhost)运行文件(php)
  15. js 移动端上拉加载下一页通用方案
  16. Kotlin从入门到放弃
  17. [NIO-2]通道和FileChannel
  18. 大数据实践:ODI 和 Twitter (二)
  19. 让div获取焦点
  20. Entity Framework学习初级篇3--LINQ TO Entities

热门文章

  1. js对象类型判断工具
  2. SQL Sever实验一 创建和删除数据库数据表
  3. PhpSpreadsheet处理表格2
  4. System.getProperty()和getenv()
  5. python通过http(multipart/form-data)上传文件的方法
  6. IO流1 --- File类的实例化 --- 技术搬运工(尚硅谷)
  7. java获取外网ip地址
  8. SDUT-3400_数据结构实验之排序三:bucket sort
  9. 洛谷P1541 乌龟棋 [2010NOIP提高组]
  10. 【水滴石穿】react-native-ble-demo