我使用this JSON-RPC client是基於AFNetworkingAFNetworking JSON-RPC預期的內容類型 - 錯誤域= AFNetworkingErrorDomain
在進行此調用後:
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的對錯誤:
error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {( "text/json", "application/json", "text/javascript" )}, got application/json-rpc" UserInfo=0xd02f680 {NSLocalizedRecoverySuggestion={"error": null, "jsonrpc": "2.0", "id": "1", "result": {"key": "38c491c894aa057d532e8b314d", "success": true}}, AFNetworkingOperationFailingURLResponseErrorKey=, NSErrorFailingURLKey=someurl, NSLocalizedDescription=Expected content type {( "text/json", "application/json", "text/javascript" )}, got 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]];
任何想法?
工作就像一個魅力!我將該行添加到此客戶端的init方法中。 非常感謝您的幫助! – Chompas
@Chompas我在Github項目中提交了這個問題,並且所有者只是修復了它。 [來源](https://github.com/wiistriker/AFNetwork-JSON-RPC-Client/blob/master/AFJSONRPCClient.m#L65) –