pat*_*ckf 5 json content-type http json-rpc http-headers
我知道 JSON RPC 不是直接用 HTTP 指定的,但我找不到合适的解决方案。问题是,哪个content-type
是正确的:
content-type: application/json
content-type: application/json-rpc
在v2和v1的官方(?)文档中,仅在这个看似已弃用的文档中没有任何有关内容类型的内容关于 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)
对我来说,最好的做法是接受两者都处于“安全”的一面?
经过快速谷歌搜索后,我看到其他人使用application/json
是我所期望的 JSON。由于文档没有指定,我想这可能会取决于服务器的实现。
也许你可以实施一个例程来尝试另一个错误的响应?不理想,但文档对你帮助不大。