regex - 在 curl 中禁用正则表达式解析
问题描述
我正在尝试卷曲一个接受正则表达式作为参数之一的 API。
我发现 curl 在这里试图变得聪明,并且正在解析正则表达式本身,而不是将其视为 URL 的一部分。因此,每次我启动 curl 命令时,它都会发出 70,000 个 HTTP 请求。它应该只做一个。
例子:https://api.example.com/v1/?regex=(123[4-5][6-7][8-9])
在这种情况下,我希望文字 HTTP 请求是.
相反,我得到:
[1/8]: https://api.example.com/v1/?regex=(123468) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123468)
curl: (6) Could not resolve host: api.example.com
[2/8]: https://api.example.com/v1/?regex=(123469) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123469)
curl: (6) Could not resolve host: api.example.com
[3/8]: https://api.example.com/v1/?regex=(123478) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123478)
curl: (6) Could not resolve host: api.example.com
[4/8]: https://api.example.com/v1/?regex=(123479) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123479)
curl: (6) Could not resolve host: api.example.com
[5/8]: https://api.example.com/v1/?regex=(123568) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123568)
curl: (6) Could not resolve host: api.example.com
[6/8]: https://api.example.com/v1/?regex=(123569) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123569)
curl: (6) Could not resolve host: api.example.com
[7/8]: https://api.example.com/v1/?regex=(123578) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123578)
curl: (6) Could not resolve host: api.example.com
[8/8]: https://api.example.com/v1/?regex=(123579) --> <stdout>
--_curl_--https://api.example.com/v1/?regex=(123579)
curl: (6) Could not resolve host: api.example.com
如何禁用 curl 的正则表达式解析?
我查了一下curl --help all
,没有关于这种解析的内容。我还检查了 curl 的手册页。那里也什么都没有;这似乎是一个完全没有记录的“有用”功能。
它似乎是 curl,而不是 shell,因为 wget 似乎不会发生这种情况,它只发出一个(失败的请求)。
试图转义括号\
似乎会阻止解析,但也会以一种看起来不正确的方式转换字符:
root@voip:/tmp# wget "https://api.example.com/v1/?regex=(123\[4-5\]\[6-7\]\[8-9\])"
--2021-11-05 11:26:03-- https://api.example.com/v1/?regex=(123%5C[4-5%5C]%5C[6-7%5C]%5C[8-9%5C])
Resolving api.example.com (api.example.com)... failed: Name or service not known.
wget: unable to resolve host address ‘api.example.com’
root@voip:/tmp# wget "https://api.example.com/v1/?regex=(123\[4-5]\[6-7]\[8-9])"
--2021-11-05 11:26:25-- https://api.example.com/v1/?regex=(123%5C[4-5]%5C[6-7]%5C[8-9])
Resolving api.example.com (api.example.com)... failed: Name or service not known.
wget: unable to resolve host address ‘api.example.com’
解决方案
要使用 {} 和 [] 禁用 URL 序列和范围,您可以使用 option -g
。
推荐阅读
- webpack - 在运行 webpack 进行摇树之前,我可以将 commonjs 模块转换为 es2015 吗?
- rest - 在进行破坏性 API 更改时,有哪些方法可以确保向后兼容性?
- ios - 如何更改 uialertcontroller 的文本字段内容?
- java - 如何使用 azure-documentdb 在 java 代码中的数据库级别配置吞吐量
- node.js - TS:无法调用其类型在动态定义时缺少调用签名的表达式,但它可以工作
- javascript - 在 ThreeJS 中获取局部对象旋转
- android - Android:使用协程测试视图模型
- android-studio - Android Studio Flutter UI 指南不起作用
- javascript - 如何让我的机器人从一组图像中选择一个随机图像
- instance - 可以将抢占式实例更改为非抢占式吗