我正在使用 AFNetworking 从服务器获取 JSON 数据,但我只返回 HTML 和一个错误,说明如下:
Expected content type {(
"text/json",
"application/json",
"text/javascript"
)}, got text/html, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7592470>}
代码如下:
NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:3000/games"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation;
operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *req, NSHTTPURLResponse *response, id jsonObject){
NSLog(@"Response: %@", jsonObject);
}
failure:^(NSURLRequest *req, NSHTTPURLResponse *response, NSError *error, id jsonObject){
NSLog(@"Error: %@", error);
}];
[operation start];
我正在使用 rails,当我使用 curl 访问页面时,服务器会发回 JSON。我想强制请求 application/json,我做错了吗?