特殊字符,如@ 和 &在 cURL POST 数据中 [英] Special characters like @ and & in cURL POST data

查看:56
本文介绍了特殊字符,如@ 和 &在 cURL POST 数据中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何包含特殊字符,例如 @ 和 &在 cURL POST 数据中?我正在尝试传递一个名称和密码,例如:

How do I include special characters like @ and & in the cURL POST data? I'm trying to pass a name and password like:

curl -d name=john passwd=@31&3*J https://www.mysite.com

这会导致问题,因为 @ 用于加载文件,而 & 用于指定多个键/值.有什么办法可以逃避这些字符吗?@& 似乎不起作用.

This would cause problems as @ is used for loading files and & for specifying more than one key/value. Is there some way I can escape these characters? @ and & don't seem to work.

推荐答案

cURL >7.18.0 有一个选项 --data-urlencode 解决了这个问题.使用这个,我可以简单地发送一个 POST 请求作为

cURL > 7.18.0 has an option --data-urlencode which solves this problem. Using this, I can simply send a POST request as

curl -d name=john --data-urlencode passwd=@31&3*J https://www.example.com

总结评论,以防混合好";和坏"里面的数据和感叹号我们可以在Windows上使用:

Summarizing the comments, in case of mixed "good" and "bad" data and exclamation marks inside we can use on Windows:

curl -d "grant_type=client_credentials&client_id=super-client&acr_values=tenant:TNT123" --data-urlencode "client_secret=XxYyZ21D8E&%fhB6kq^mXQDovSZ%Q*!ipINme"  https://login.example.com/connect/token

这篇关于特殊字符,如@ 和 &在 cURL POST 数据中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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