سؤال

I'm using this JSON-RPC client that is based on AFNetworking

After making this call:

    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]);
}];

I'm getting this in the NSLog for error:

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/>}

What I also don't understand is why the response is appearing with all the correct data (highlighted in bold).

So far, this is what I tried:

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

Any ideas?

هل كانت مفيدة؟

المحلول

Your first attempted solution of [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"application/json-rpc"]]; probably would have worked if you were having this issue with just AFJSONRequestionOperation but since you are using this client that isn't a subclass of AFHTTPRequestOperation so it doesn't respond to this method.

That might be a viable solution if you alter the code of the client you are using. In the source code an AFJSONRequestOperation called operation is created, if you attempted to use [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"application/json-rpc"]]; somewhere around here, you may be able to fix the issue.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top