我使用php-aria2下载远程文件。但是所有对127.0.0.1:8100/jsonrpc
的请求都返回null。aria2c在命令行中运行良好。
当我从命令行运行此程序时
curl http://127.0.0.1:6800/jsonrpc -H "Content-Type: application/json" -H "Accept: application/json" --data '{{"jsonrpc": "2.0","id":1, "method": "aria2.getGlobalStat", "params":[]}' -G
我得到了:
curl:(52(来自服务器的空回复
有人知道怎么解决这个问题吗?
简单的修复方法是删除多余的"{"并使用POST而不是GET:
curl http://127.0.0.1:6800/jsonrpc -H "Content-Type: application/json" -H "Accept: application/json" --data '{"jsonrpc": "2.0","id":1, "method": "aria2.getGlobalStat", "params":[]}'
aria2在GET请求中支持JSON-RPC,但它需要正确编码。看见http://aria2.sourceforge.net/manual/en/html/aria2c.html#json-rpc使用http获取
curl -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","id":"qwer","method":"aria2.getGlobalStat", "params": []}' http://localhost:6800/jsonrpc
如果我们--rpcsecret=TOKEN需要这个
curl -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","id":"qwer","method":"aria2.getGlobalStat", "params": ["token:TOKEN"]}' http://localhost:6800/jsonrpc
curl http://127.0.0.1:6800/jsonrpc --data "{"jsonrpc": "2.0","id":1, "method": "aria2.getGlobalStat", "params":[]}"
或
curl http://127.0.0.1:6800/jsonrpc --data "{"""jsonrpc""": """2.0""","""id""":1, """method""": """aria2.getGlobalStat""", """params""":[]}"