我正在尝试编写一个用于测试的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) 我正在写一个bash脚本,我试图提交一个post变量,但是wget将它视为多个URL我相信因为它不是URLENCODED ...这是我的基本思想
MESSAGE='I am trying to post this information'
wget -O test.txt http://xxxxxxxxx.com/alert.php --post-data 'key=xxxx&message='$MESSAGE''
Run Code Online (Sandbox Code Playgroud)
我收到错误并且alert.php没有得到post变量加上它很难说
无法解决我无法解决我无法解决尝试..等等.
我上面的例子是一个简单的有点sudo示例,但我相信如果我可以对其进行url编码,它会通过,我甚至尝试过像:
MESSAGE='I am trying to post this information'
MESSAGE=$(php -r 'echo urlencode("'$MESSAGE'");')
Run Code Online (Sandbox Code Playgroud)
但PHP错误..任何想法?如何在没有php执行的情况下传递$ MESSAGE中的变量?