سؤال

I know that JSON RPC is not directly specified with HTTP, but I cannot find a proper solution for this. The question is, which content-type is correct:

  1. content-type: application/json
  2. content-type: application/json-rpc
  3. both?

In the official (?) doc for v2 and v1 there is nothing about content-types only in this seemingly deprecated document about JSON rcp v1.2 there is the definition of (2) but optional (1).

By investigating the popular jsonRPC4J java lib that uses v2 spec I found in the client that they set (2):

    /**
     * Prepares a connection to the server.
     * @param extraHeaders extra headers to add to the request
     * @return the unopened connection
     * @throws IOException 
     */
    protected HttpURLConnection prepareConnection(Map<String, String> extraHeaders)
        throws IOException {

        ...
        con.setRequestProperty("Content-Type", "application/json-rpc");

        // return it
        return con;
    }

For me best practice would be to just accept both to be on the "safe" side?

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

المحلول

After a quick google search I see others using application/json which is what I would have expected for JSON. Since the documentation doesn't specify, I imagine this could be hit or miss depending on the implementation of the server.

Maybe you could implement a routine that tried the other on a bad response? Not ideal, but the docs aren't helping you much.

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