小编Jav*_*Odd的帖子

在 curl 中拆分标题和内容

curl -L -i google.com
Run Code Online (Sandbox Code Playgroud)

我想将响应中的 HEADER 和 CONTENT 拆分为两个变量

curl -I google.com
curl -L google.com
Run Code Online (Sandbox Code Playgroud)

我不能使用这两个,因为我打算将它与 10000 多个链接一起使用

Header 和 Content 都可以有三个或更多的空行,所以每次都不能拆分空行


我找到了答案

b=$(curl -LsD h google.com)
h=$(<h)
echo "$h$b"
Run Code Online (Sandbox Code Playgroud)

这段代码也有效

curl -sLi google.com | 
awk -v bl=1 'bl{bl=0; h=($0 ~ /HTTP\/1/)} /^\r?$/{bl=1} {print $0>(h?"header":"body")}'

header=$(<header)
body=$(<body)
Run Code Online (Sandbox Code Playgroud)

linux bash shell curl http-headers

5
推荐指数
1
解决办法
1605
查看次数

标签 统计

bash ×1

curl ×1

http-headers ×1

linux ×1

shell ×1