首页 > 解决方案 > 如何使用 Curl 发送参数和值?

问题描述

我正在尝试使用 GET 向网页发送 curl 请求以发送参数及其值。它适用于前两个,但最后一个“a-listibg-pro”由于我假设的连字符而不断给我带来麻烦。请帮忙

 curl -X GET <url>?"type"="fruit"&"number"="two hundred and one"&"a-listing-pro"="yes but conditional"

标签: htmllinuxcurlparameters

解决方案


连字符是 URL 安全的,所以这不应该是问题。

请注意,空格和其他特殊字符在用于查询字符串之前需要进行 URL 编码。

https://www.w3schools.com/tags/ref_urlencode.ASP

空格通常用%20or编码+,因此您的字符串可以用作

curl "https://example.com/?type=fruit&number=two%20hundred%20and%20one&a-listing-pro=yes%20but%20conditional"

(卷曲默认为GET所以不需要-x


推荐阅读