来自终端的 HTTP 请求的 XML 输出

来自终端的 HTTP 请求的 XML 输出

我正在HTTP使用curl终端发送请求,并希望查看或保存输出(默认情况下输出xml)。

以下是我使用的代码:

curl https://catalogue.onda-dias.eu/dias-catalogue/Products?$search="name:S1A_IW_OCN__2SDV_20170904T063918_20170904T063943_018222_01EA1A_8E10.zip"

输出包含很多(在我看来)随机文本(见图 1)

如果我在浏览器上运行相同的http请求(见图 2),我会得到 xml 中的输出(我需要 xml 来提取一次包含的参数)

卷曲在此处输入图片描述

答案1

您可以从开发人员工具中复制 curl 命令:

图片更多细节

核实:

curl 'https://catalogue.onda-dias.eu/dias-catalogue/Products?$search=%22name:S1A_IW_OCN__2SDV_20170904T063918_20170904T063943_018222_01EA1A_8E10.zip%22' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' -H 'Sec-Fetch-Mode: navigate' -H 'Sec-Fetch-User: ?1' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'Sec-Fetch-Site: none' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: ru-RU,ru;q=0.9' -H 'Cookie: SRVNAME=N02' --compressed

只要它有效,您可以删除不必要的标题:

curl 'https://catalogue.onda-dias.eu/dias-catalogue/Products?$search=%22name:S1A_IW_OCN__2SDV_20170904T063918_20170904T063943_018222_01EA1A_8E10.zip%22' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3'

或简短版本(-H 'Accept: application/xml仅添加):

curl 'https://catalogue.onda-dias.eu/dias-catalogue/Products?$search=%22name:S1A_IW_OCN__2SDV_20170904T063918_20170904T063943_018222_01EA1A_8E10.zip%22' -H 'Accept: application/xml'

相关内容