我需要使用 POST JSON-RPC 请求检查后端。尝试了所有方法,但都不起作用,后端无法解析正文。知道我做错了什么吗?
curl -vX POST http://localhost:5555 --data '{"jsonrpc":"2.0", "method":"xxx", "params":[],"id":1}'
* Connected to localhost (127.0.0.1) port 5555 (#0)
> POST / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:5555
> Accept: */*
> Content-Length: 53
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 63 out of 63 bytes
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Sat, 22 Aug 2015 15:28:33 GMT
< Content-Length: 39
<
{"id":1,"jsonrpc":"2.0","result":true}
我尝试了这个配置:
option httpchk POST / HTTP/1.1\r\nContent-Type: application/json\r\nContent-Length: 53\r\n\r\n{"jsonrpc":"2.0", "method":"xxx", "params":[],"id":1}
答案1
您可能需要正确地转义用于检查的字符串。
你有
option httpchk POST / HTTP/1.1\r\nContent-Type: application/json\r\nContent-Length: 53\r\n\r\n{"jsonrpc":"2.0", "method":"xxx", "params":[],"id":1}
虽然我认为这可能会更好
option httpchk POST / HTTP/1.1\r\nContent-Type:\ application/json\r\nContent-Length:\ 53\r\n\r\n{"jsonrpc":"2.0","method":"xxx","params":[],"id":1}
:
不同之处在于和标头后面的斜杠Content-Type
以及Content-Length
删除了 JSON“主体”中的所有空格。
我还没有测试过这个,但我不明白为什么它不起作用。