2015-03-25 84 views
0

如何将url保存到一个文件中并且旁边的响应来自服务器? 我希望他在文件的唯一地址,并从服务器回答。 例子:cURL,只保存http响应和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 

什么卷曲我必须使用选项才能得到完全的结果?

回答

0

不知道里面有卷曲特定选项,选择标题字段,但脚本可以帮助你

#!/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