我正在使用这个基于 AFNetworking 的JSON-RPC 客户端
拨打此电话后:
AFJSONRPCClient *client = [[AFJSONRPCClient alloc] initWithURL:[NSURL URLWithString:kAPIHost]];
[client invokeMethod:@"auth.login"
withParameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {
//success handling
completionBlock(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//error handling
NSLog(@"error: %@", [error description]);
}];
我在 NSLog 中得到这个错误:
错误:错误域=AFNetworkingErrorDomain 代码=-1016“预期的内容类型 {(“text/json”、“application/json”、“text/javascript”)},得到了 application/json-rpc”UserInfo=0xd02f680 {NSLocalizedRecoverySuggestion={ “错误”:空,“jsonrpc”:“2.0”,“id”:“1”,“结果”:{“key”:“38c491c894aa057d532e8b314d”,“成功”:true}},AFNetworkingOperationFailingURLResponseErrorKey=,NSErrorFailingURLKey=someurl, NSLocalizedDescription=预期的内容类型 {( "text/json", "application/json", "text/javascript" )},得到 application/json-rpc, AFNetworkingOperationFailingURLRequestErrorKey=http://rpc.development.hotelzilla.net/>}
我也不明白为什么会出现所有正确数据的响应(以粗体突出显示)。
到目前为止,这是我尝试过的:
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"application/json-rpc"]];
// Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
[self setDefaultHeader:@"Accept" value:@"application/json-rpc"];
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
有任何想法吗?