我想发送一个json请求并在post数据中嵌入一个变量。 我做了一点研究,并提出了围绕变量的单引号。Bash脚本:在curl中使用字符串变量JSON Post data
#!/bin/bash
FILENAME="/media/file.avi"
curl -i -X POST -H "Content-Type: application/json" —d '{"jsonrpc": "2.0", "method": "Player.Open", "params":{"item":{"file":"'$FILENAME'"}}}' http://192.167.0.13/jsonrpc
不幸的是我得到了一些错误:
curl: (6) Couldn't resolve host '—d'
curl: (3) [globbing] nested braces not supported at pos 54
HTTP/1.1 200 OK
Content-Length: 76
Content-Type: application/json
Date: Wed, 29 Jan 2014 19:16:56 GMT
{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}
Appearently存在一些问题与撑杆和HTTP应答状态,即不能被执行的命令。我的代码在这里有什么问题? 谢谢!
这是我的curl
版本:
curl 7.30.0 (mips-unknown-linux-gnu) libcurl/7.30.0 OpenSSL/0.9.8y
Protocols: file ftp ftps http https imap imaps pop3 pop3s rtsp smtp smtps tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL
这似乎是一个高概率候选人'卷曲:(6)无法解析主机“ - D''。做一个“人卷曲”并搜索“--data”。祝你好运。 – shellter
“d”选项之前的字符似乎是一些特殊的印刷破折号? – halfbit
@halfbit:赶上! (好名字!) – shellter