我想知道是否可以通过使用常规字符串以及来自文件的数据发布json数据来完成命令行的卷曲
我试过了,
curl -X POST -H "Content-Type: application/json" -H "Accept: applicaton/json" -d '{"port":"10001", "nodeID": "testnode", "ca": '"`cat cert.pem`"'}' http://localhost:1215/net/tunnel
但那说错误
SyntaxError: Unexpected number
方法不正确还是我有错误?
更新
root@ubuntu:/home/user/work/derivation/keys# curl -X POST -H "Content-Type: application/json" -H "Accept: applicaton/json" -d "{\"port\":\"10001\", \"nodeID\": \"testnode\", \"ca\": \"<tilde>cat cert.pem<tilde>\"}" http://localhost:1215/net/tunnel
SyntaxError: Unexpected token
at Object.parse (native)
at IncomingMessage.<anonymous> (/home/user/work/boomerang/node_modules/express/node_modules/connect/lib/middleware/json.js:76:27)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at _stream_readable.js:920:16
at process._tickDomainCallback (node.js:459:13)root@ubuntu:/home/user/work/derivation/keys#
谢谢!
答案 0 :(得分:1)
是的,您可以使用-d @filename.txt
:
curl -X POST -H "Content-Type: application/json" -H "Accept: applicaton/json" -d @filename.txt http://localhost:1215/net/tunnel
但是你当前的命令也应该有效。试试这个:
curl -X POST -H "Content-Type: application/json" -H "Accept: applicaton/json" -d "{\"port\":\"10001\", \"nodeID\": \"testnode\", \"ca\": \"'cat cert.pem'\"}" http://localhost:1215/net/tunnel