简体   繁体   English

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

[英]What is the correct content-type header for Json RPC v2 over HTTP?

I know that JSON RPC is not directly specified with HTTP, but I cannot find a proper solution for this.我知道 JSON RPC 不是直接用 HTTP 指定的,但我找不到合适的解决方案。 The question is, which content-type is correct:问题是,哪种content-type是正确的:

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

By investigating the popular jsonRPC4J java lib that uses v2 spec I found in the client that they set (2):通过调查使用 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;
    }

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.在快速谷歌搜索后,我看到其他人使用application/json ,这是我对 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM