【问题标题】:What is the correct content-type header for Json RPC v2 over HTTP?Json RPC v2 over HTTP 的正确内容类型标头是什么?
【发布时间】:2013-12-11 19:04:22
【问题描述】:

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

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

official (?) doc for v2v1 中没有关于内容类型的内容,只有在this seemingly deprecated document 关于 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;
    }

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

【问题讨论】:

    标签: json http http-headers content-type json-rpc


    【解决方案1】:

    在谷歌快速搜索后,我看到其他人使用application/json,这是我对 JSON 的预期。由于文档没有指定,我想这可能会根据服务器的实现而被命中或错过。

    也许您可以实施一个例程,在一个不好的响应中尝试另一个?不理想,但文档对您帮助不大。

    【讨论】:

      猜你喜欢
      • 2010-10-03
      • 1970-01-01
      • 2014-06-03
      • 2015-08-10
      • 2016-04-17
      • 2013-03-15
      • 1970-01-01
      相关资源
      最近更新 更多