使用cURL的多行GET请求

f4t66c6m  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(160)

我想格式化一个有效的GET请求,使其更易于阅读。有很多参数,将来可能会更多。那么,在文档中,如何格式化cURL命令中的长URL呢?最好将每个queryparam显示在一个换行符中。

curl --header 'header1: XXXXXX' 'https://localhost/api/similar?word=science&target=en&target=fr&target=bg&target=ar&target=fr&source=en&limit=10&score=0.5'

请注意有效的重复参数target(根据服务器端的查询解析器将其解释为数组)。
编辑:这是我已经尝试过但没有成功的:

curl -XGET -G 'https://localhost/api/similar?' \
-d word=science \
-d target=en \
-d target=fr \
-d target=bg \
-d target=ar \
-d target=fr \
-d source=en \
-d limit=10 \
-d score=0.5

不幸的是,这不起作用

gkn4icbw

gkn4icbw1#

非常接近了:)只需将-XGET替换为-get,它就可以工作了

curl --get 'https://localhost/api/similar?' \
-d word=science \
-d target=en \
-d target=fr \
-d target=bg

还要注意,\多行shell调用的语法是特定于posix shell的,这意味着它不能在Microsoft Windows上工作,在Windows的cmd中,它将是

curl --get 'https://localhost/api/similar?' ^
-d word=science ^
-d target=en ^
-d target=fr ^
-d target=bg

(and再次强调^是Windows独有的,因此无法在posix shell上运行~)

相关问题