通过 HTTP 的 Json RPC v2 的正确内容类型标头是什么?

pat*_*ckf 5 json content-type http json-rpc http-headers

我知道 JSON RPC 不是直接用 HTTP 指定的,但我找不到合适的解决方案。问题是,哪个content-type是正确的:

  1. content-type: application/json
  2. content-type: application/json-rpc
  3. 两个都?

v2v1的官方(?)文档中,仅在这个看似已弃用的文档中没有任何有关内容类型的内容关于 JSON rcp v1.2 的文档中,有 (2) 的定义,但可选 (1) 的定义。

通过调查使用 v2 规范的流行jsonRPC4J java lib,我在他们设置的客户端中发现了 (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;
    }
Run Code Online (Sandbox Code Playgroud)

对我来说,最好的做法是接受两者都处于“安全”的一面?

dm7*_*m78 3

经过快速谷歌搜索后,我看到其他人使用application/json是我所期望的 JSON。由于文档没有指定,我想这可能会取决于服务器的实现。

也许你可以实施一个例程来尝试另一个错误的响应?不理想,但文档对你帮助不大。