curl是什么?
全称CommandLine URL 或 CommandLine Uniform Resource Locator,在命令行方式下工作,利用URL的语法进行数据的传输或者文件的传输。是一个用来与服务器之间传输数据的工具。
功能:curl提供了一大堆非常有用的功能,包括代理访问、用户认证、ftp上传下载、HTTP POST、SSL连接、cookie支持、断点续传等。
以下是常用的curl命令:
1.curl url (发送get请求,返回该网址的html信息)curl www.baidu.com
新闻 hao123 地图 视频 贴吧 更多产品百度一下,你就知道
关于百度 about Baidu
©2017 Baidu 使用百度前必读 意见反馈 京ICP证030173号
2.curl -i url(返回该网址的html信息+协议头部信息).HTTP/1.1 200 OK Accept-Ranges: bytes Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform Connection: keep-alive Content-Length: 2381 Content-Type: text/html Date: Wed, 16 Feb 2022 07:34:45 GMT Etag: "588604d8-94d" Last-Modified: Mon, 23 Jan 2017 13:27:52 GMT Pragma: no-cache Server: bfe/1.0.8.18 Set-cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/新闻 hao123 地图 视频 贴吧 更多产品百度一下,你就知道
关于百度 about Baidu
©2017 Baidu 使用百度前必读 意见反馈 京ICP证030173号
3.curl -x proxy url(使用代理获取网页html信息)这里我使用的代理可以访问google
curl -x http://10.10.8.66:1081 https://google.cn/webhp?source=g_cn
4.curl -I url(仅返回请求头部信息)302 Moved 302 Moved The document has moved here.
curl -I www.baidu.com
HTTP/1.1 200 OK Accept-Ranges: bytes Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform Connection: keep-alive Content-Length: 277 Content-Type: text/html Date: Thu, 17 Feb 2022 06:02:56 GMT Etag: "575e1f72-115" Last-Modified: Mon, 13 Jun 2016 02:50:26 GMT Pragma: no-cache Server: bfe/1.0.8.185.curl -v url(返回端口连接信息,http请求头部信息,网页html信息)
-v 参数表示显示一次 http 通信的整个过程,包括端口连接和 http request 头信息。
curl -v www.baidu.com
* Rebuilt URL to: www.baidu.com/ * Trying 14.215.177.38... * TCP_NODELAY set * Connected to www.baidu.com (14.215.177.38) port 80 (#0) > GET / HTTP/1.1 > Host: www.baidu.com > User-Agent: curl/7.54.0 > Accept: */* > < HTTP/1.1 200 OK < Accept-Ranges: bytes < Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform < Connection: keep-alive < Content-Length: 2381 < Content-Type: text/html < Date: Fri, 18 Feb 2022 06:15:59 GMT < Etag: "588604cf-94d" < Last-Modified: Mon, 23 Jan 2017 13:27:43 GMT < Pragma: no-cache < Server: bfe/1.0.8.18 < Set-cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/ <新闻 hao123 地图 视频 贴吧 更多产品百度一下,你就知道
关于百度 about Baidu
©2017 Baidu 使用百度前必读 意见反馈 京ICP证030173号
* Connection #0 to host www.baidu.com left intact


