我试图使用接受正则表达式作为参数之一的API。
我发现curl在这里很聪明,并且解析正则表达式本身,而不是把它作为URL的一部分。因此,每当我启动curl命令时,它就会发出70000个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,而不是shell,因为wget似乎没有发生这种情况,因为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’发布于 2021-11-05 16:03:58
若要使用{}和[]禁用URL序列和范围,可以使用选项-g。
https://stackoverflow.com/questions/69852393
复制相似问题