我正在尝试使用ansible的uri模块来模仿curl命令,我需要在上传XML文件时传递选项。
我的curl命令通过-F, --form <name=content>
传递了多个选项我无法在Ansible's uri docs上找到等效选项
有什么想法吗?
答案 0 :(得分:0)
假设此处有非二进制表单内容,您可以在此处指定两个标头:
"Content-type: application/x-www-form-urlencoded"
body_format: raw
这意味着你要给它一个完整的原始url编码的主体,其中包含所有的表单参数。
没有JSON (param=value
)
一般格式为:
PARAM = <强> 网址编码值换PARAM 强>&安培; param2的= <强> 网址编码值换param2的 等
使用JSON
将Content-Type
标头设置为application/json
,您可以像这样发送直接JSON:
{"param1":"value","param2":"value","param3":6}
如果将JSON作为表单的子集发送,它将是这样的:
records='{"param1":"value","param2":"value","param3":6}'&action=submit
但对此的支持各不相同。这样做的正确方法是使用set Content-type: application/x-www-form-urlencoded
发送整个事情:
records=%7B%22param1%22%3A%22value%22%2C%22param2%22%3A%22value%22%2C%22param3%22%3A6%7D&action=submit
来自Ansible(格式已修改):
body_format(在2.0中添加)(no | raw | json)
序列化格式 的身体。设置为json时,如果需要,对body参数进行编码, 并相应地自动设置Content-Type标头。截至2.3 设置为json时,可以覆盖Content-Type
标头 通过标题选项。