Tom*_*usX 28 json node.js ios ios7 afnetworking-2
我正在使用AFNetworking 2.0从我正在构建的服务(localhost现在开始)中读取JSON .很正常的东西.
Node正在发送JSON,如下所示:
res.setHeader('Content-Type','application/json');
res.end( JSON.stringify(...));
Run Code Online (Sandbox Code Playgroud)
我的iOS首次传递代码试图像这样读取数据:
typedef void(^NextBlock)();
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:self.newestTimestampURL.absoluteString
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject)
{
//NSDictionary *response =
NSLog(@"got %@", responseObject );
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"fail %@", error );
}];
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: text/plain" UserInfo=0xb783e30 {NSErrorFailingURLKey=http://localhost:3000/api/v1/log/newest, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xb656a70> { URL: http://localhost:3000/api/v1/log/newest } { status code: 200, headers {
Connection = "keep-alive";
ContentType = "application/json";
Date = "Fri, 27 Dec 2013 20:58:50 GMT";
"Transfer-Encoding" = Identity;
} }, NSLocalizedDescription=Request failed: unacceptable content-type: text/plain}
Run Code Online (Sandbox Code Playgroud)
我可以卷曲(-i)url http://localhost:3000/api/v1/log/newest并获取我期望的数据,并且它是application/json,如预期的那样.如果我在我的Web浏览器中加载该数据,我会按照预期的工具检查器获得JSON.
但是使用AFNetworking,我得到了这个神秘的"不可接受的内容类型:text/plain"错误.任何的想法?
注意:我之前从未使用AFNetworking,所以我可能错误地使用它.
KIO*_*KIO 40
似乎服务器正在发送"text/html",默认情况下不支持此类型.为"acceptableContentTypes"添加@"text/html"
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
Run Code Online (Sandbox Code Playgroud)
小智 9
为我工作.
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37820 次 |
| 最近记录: |