我想知道如何使用CURL在「jayson」npm包中查找可從此處獲得的nodejs https://github.com/tedeh/jayson。我在服務器端使用下面的測試程序。節點運行正常,並用錯誤輸出響應Curl。沒有辦法找到又該捲曲傳遞或如何在節點計劃進行更改:如何使用curl查詢jayson(nodejs)
var jayson = require(__dirname + '/../..');
var server = jayson.server({
echo: function(msg, callback) {
if(msg != null)
callback(null, msg);
},
add: function(a, b, callback) {
if((a!= null) && (b!= null))
callback(null, a + b);
}
});
server.http().listen(90);
這是curl命令:
$ curl -v -i -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "id":"curltest", "method":"echo", "params": ["hello"] }' http://localhost:90
,這是的NodeJS回答捲曲如果收到curl命令不符合傑森:
* About to connect() to localhost port 90 (#0)
* Trying 127.0.0.1...
* connected
* Connected to localhost (127.0.0.1) port 90 (#0)
> POST/HTTP/1.1
> User-Agent: curl/7.28.1
> Host: localhost:90
> Accept: */*
> Content-Type: application/json
> Content-Length: 16
>
* upload completely sent off: 16 out of 16 bytes
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Length: 79
Content-Length: 79
< Content-Type: application/json
Content-Type: application/json
< Date: Tue, 25 Mar 2014 19:26:21 GMT
Date: Tue, 25 Mar 2014 19:26:21 GMT
< Connection: keep-alive
Connection: keep-alive
<
* Connection #0 to host localhost left intact
{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid request"}}* Closing connection #0
非常感謝您的幫助, 雷米
好感謝暫定!順便說一下,我正在使用Cygwin的Curl。不幸的是你的修復給了我同樣的錯誤。我已根據您的建議更新了說明。 – user1680283
@ user1680283你的curl命令可以。不是取決於'node.js'老闆來處理這個問題! –