我正在尝试编写一个用于测试的bash脚本,它接受一个参数并通过curl将其发送到网站.我需要对值进行url编码,以确保正确处理特殊字符.做这个的最好方式是什么?
这是我到目前为止的基本脚本:
#!/bin/bash
host=${1:?'bad host'}
value=$2
shift
shift
curl -v -d "param=${value}" http://${host}/somepath $@
Run Code Online (Sandbox Code Playgroud) 我正在尝试DELETE使用CURL 发送带有url参数的请求.我在做:
curl -H application/x-www-form-urlencoded -X DELETE http://localhost:5000/locations` -d 'id=3'
Run Code Online (Sandbox Code Playgroud)
但是,服务器没有看到参数id = 3.我尝试使用一些GUI应用程序,当我将URL传递为:时http://localhost:5000/locations?id=3,它可以工作.我真的宁愿使用CURL而不是这个GUI应用程序.任何人都可以指出我做错了什么?
当使用类似的东西进行curl POST调用时,... | curl -XPOST --data @- https://example.com/我是否也可以在命令行上对一些url参数进行url编码(使用curl本身,而不是bash函数),而不必自己对其进行编码并将它们放入curl的url参数中?
所以我希望 POST Body不进行urlencoded,但 url 参数在同一个curl 命令中进行url 编码。
例如:
echo '{"username":"a","password": [1,2]}' | curl --header "Content-Type: application/json" --request POST -d@- --data-urlencode "filter=." http://localhost:8080
Run Code Online (Sandbox Code Playgroud)
似乎没有做我想做的事,而且我已经对我的https://localhost:8080/网址进行了后缀处理?filter...,当参数需要大量编码时,我宁愿避免使用它。