Skip to content

回复:JSON-RPC 多次调用 ​

原始发布页

打开来源页面
查看 1 个交叉存档

它重复输出标头显然是个错误。

我当时试图遵循 1.0 规范:http://json-rpc.org/wiki/specification 它要求支持多次调用。

我认为他们的意思是像下面这样,但我不确定:

请求:

json
{"method": "postMessage", "params": ["大家好!"], "id": 99}
{"method": "postMessage", "params": ["我有一个问题:"], "id": 101}

回复:

json
{"result": 1, "error": null, "id": 99}
{"result": 1, "error": null, "id": 101}

我记不起来自己是在哪里看到错误回复应该返回 HTTP 状态码 500 的。如果它包含多个响应,其中一个是错误,我不知道这是否会让整个响应的状态码都变成 500,我猜会。也许它应该总是返回 200。我记得好像有人提到过 500 可能会造成问题。

这个问题大概要在 0.3.3 之后才会修复。在那之前,请只使用单次调用。我怀疑是否有任何 JSON-RPC 软件包支持多次调用,可能没有。

在尝试修复之前,如果我们能更准确地确定多次调用究竟应该如何工作——如果它确实应该工作的话——以及为错误响应返回 HTTP 状态码 500 是否正确,那就好了。

英文原文 ​

展开英文原文

Obviously it's a bug that it repeats the header.

I was trying to follow the 1.0 spec: http://json-rpc.org/wiki/specification It called for multiple invocation.

I think they mean it's like this, but I'm not sure:

Post:

json
{"method": "postMessage", "params": ["Hello all!"], "id": 99}
{"method": "postMessage", "params": ["I have a question:"], "id": 101}

Reply:

json
{"result": 1, "error": null, "id": 99}
{"result": 1, "error": null, "id": 101}

I can't remember where I think I saw that it's supposed to send back HTTP status 500 for an error reply. If it contains multiple responses and one is an error, I wonder if that makes the status 500 for the whole thing, I guess so. Maybe it should always return 200. I think someone sounded like the 500 might be causing a problem.

This probably gets fixed after 0.3.3. Until then, just use single invocation. I wonder if any JSON-RPC package even supports multiple invocation, probably not.

It would be nice if we could pin down better how multiple-invocation is supposed to work, if at all, before trying to fix it, and whether returning HTTP status 500 for error response is right.

为历史保存,为中文读者整理。每篇档案均附来源与英文原文。