首页 技术 正文
技术 2022年11月10日
0 收藏 994 点赞 4,200 浏览 2055 个字

wget is a Linux command-line utility for retrieving files
from the web, via HTTP, HTTPS and FTP protocols. When you are using wget to
download a file at a particular HTTP url, wget sends an appropriate
HTTP request to a destination web server.

To view default HTTP request header being sent by wget, you
can use “-d” option.

$ wget -d http://www.google.com/

---request begin---
GET / HTTP/1.0
User-Agent: Wget/1.12 (linux-gnu)
Accept: */*
Host: www.google.com
Connection: Keep-Alive---request end---

Sometimes you may want to customize the default HTTP request header used by wget.
For example, you may want to customize “User-Agent” field as some sites rely on “User-Agent” string to block robots like wget to
retrieve their content. You may want to add an additional “Accept-Encoding” field in order to test encoding schemes of your web server. In some other cases, you may need to set “Host” field properly to be able to access a web server running on name-based virtual
hosting.

wget allows you to send an HTTP request with custom HTTP headers.
To supply custom HTTP headers, use “–header” option. You can use “–header” option as many time as you want in a single run.

$ wget -d –header=”User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11″ –header=”Referer: http://xmodulo.com/” –header=”Accept-Encoding: compress, gzip” http://www.google.com/

---request begin---
GET / HTTP/1.0
User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11
Accept: */*
Host: www.google.com
Connection: Keep-Alive
Referer: http://xmodulo.com/
Accept-Encoding: compress, gzip---request end---

If you would like to permanently set the default HTTP request header you want to use with wget,
you can use ~/.wgetrc configuration file. You can specify as many header fields as you want in ~/.wgetrc.

$ vi ~/.wgetrc

header = User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11
header = Referer: http://xmodulo.com/
header = Accept-Encoding: compress, gzip

Once you have configured ~/.wgetrc, you no longer need to use “–header” option with wget.

curl is another command-line tool with similar functionality
as wget. The curl utility
also allows you to set a custom HTTP header. Refer to this
guideline
 for detail on curl.

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902