Jav*_*Odd 5 linux bash shell curl http-headers
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)
您可以使用这个脚本:
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)