如何使用 CURL 将 shell 脚本作为 POST 正文发送到 Tornado?
How can one use CURL to send a shell script as the POST body to Tornado?
我不清楚 Tornado 期望如何解析所有内容类型的正文参数。它对 JSON 和表单数据有意义,但对于其他正文内容类型,我不清楚如何使用 CURL 格式化请求以使其正常工作。
Question: How can one use CURL to send a shell script as the POST body to Tornado? What is the formatting for the body arguments?
我尝试过的:
curl -X POST -H "Content-Type: application/x-sh" http://localhost:8888/ -d script='#!/bin/bash \necho "scale=500\; 4*a(1)" | bc -l'
我希望或期望这样做的是让 Tornado 处理 HTTP 正文,以便 (1) 正文参数是 script
,(2) 对应的值是 shell 计算圆周率的脚本:
#!/bin/bash
echo "scale=500\; 4*a(1)" | bc -l
相反,我只是得到一个 400: Bad Request
错误,我的调试日志显示 self.request.body_arguments
的值是一个空字典 {}
。
您正在使用此 header - Content-Type: application/x-sh
发送 POST 数据。但是 Tornado 只支持 application/x-www-form-urlencoded
解析提交的 form/POST 数据。
只需使用 Content-Type: application/x-www-form-urlencoded
提交数据,Tornado 将使提交的数据在 body_arguments
中可用。
我不清楚 Tornado 期望如何解析所有内容类型的正文参数。它对 JSON 和表单数据有意义,但对于其他正文内容类型,我不清楚如何使用 CURL 格式化请求以使其正常工作。
Question: How can one use CURL to send a shell script as the POST body to Tornado? What is the formatting for the body arguments?
我尝试过的:
curl -X POST -H "Content-Type: application/x-sh" http://localhost:8888/ -d script='#!/bin/bash \necho "scale=500\; 4*a(1)" | bc -l'
我希望或期望这样做的是让 Tornado 处理 HTTP 正文,以便 (1) 正文参数是 script
,(2) 对应的值是 shell 计算圆周率的脚本:
#!/bin/bash
echo "scale=500\; 4*a(1)" | bc -l
相反,我只是得到一个 400: Bad Request
错误,我的调试日志显示 self.request.body_arguments
的值是一个空字典 {}
。
您正在使用此 header - Content-Type: application/x-sh
发送 POST 数据。但是 Tornado 只支持 application/x-www-form-urlencoded
解析提交的 form/POST 数据。
只需使用 Content-Type: application/x-www-form-urlencoded
提交数据,Tornado 将使提交的数据在 body_arguments
中可用。