cURL,仅将http响应和url保存到同一文件中

时间:2015-03-25 12:28:28

标签: shell curl sh

如何将url保存到文件以及服务器响应旁边? 我希望他在仅文件地址并从服务器回答。 例如:

#!/bin/sh -e
curl -I http://stackoverflow.com/help/badges >> result.txt

在输出文件中现在收到这样的结果:

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 105125
Content-Type: text/html; charset=utf-8
X-Frame-Options: SAMEORIGIN
X-Request-Guid: 9d649d74-9d9b-4d89-aa1e-351eeb0ed03f
Set-Cookie: prov=bcbf7794-8fcd-4211-8322-a8df854c00ac;  
domain=.stackoverflow.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; 
path=/; HttpOnly Date: Wed, 25 Mar 2015 12:13:35 GMT

但是我想在输出文件中收到这样的结果:

http://stackoverflow.com/help/badges -HTTP/1.1 200 OK

我必须使用哪些卷曲选项来获得这个结果?

1 个答案:

答案 0 :(得分:0)

不确定curl中是否有特定选项来选择标题字段,但脚本可以帮助您

#!/bin/sh
url_0='http://stackoverflow.com/help/badges'
echo -n $url_0 -
curl -sI $url_0 | grep 'HTTP'
exit

输出:

http://stackoverflow.com/help/badges -HTTP/1.1 200 OK