如何urlen为curl命令code数据? [英] How to urlencode data for curl command?

查看:163
本文介绍了如何urlen为curl命令code数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个用于测试的bash脚本,需要一个参数,并将其通过卷曲网站。我需要给url EN code值,以确保特殊字符正确处理。什么是做到这一点的最好方法是什么?

下面是我的基本的脚本到目前为止:

 #!/斌/庆典
主机= $ {1:招待不周}
价值= $ 16
转移
转移
卷曲-v -d参数= $ {}值的http:// $ {HOST} / somepath $ @


解决方案

只需使用卷曲--data-urlen code


  

这个帖子的数据,类似于其他 - 数据与此进行URL编码例外选项。为了CGI兼容,在<数据方式> 部分应该用名后跟分隔符和内容规范的开始。


实例:

 卷曲--data-urlen codeparamName配置=参数www.example.com

更多信息请访问:男人卷曲

I am trying to write a bash script for testing that takes a parameter and sends it through curl to web site. I need to url encode the value to make sure that special characters are processed properly. What is the best way to do this?

Here is my basic script so far:

#!/bin/bash
host=${1:?'bad host'}
value=$2
shift
shift
curl -v -d "param=${value}" http://${host}/somepath $@

解决方案

Just use curl --data-urlencode.

This posts data, similar to the other --data options with the exception that this performs URL-encoding. To be CGI-compliant, the <data> part should begin with a name followed by a separator and a content specification.

Example usage:

curl --data-urlencode "paramName=param" www.example.com

See more at: man curl.

这篇关于如何urlen为curl命令code数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆