curl下载安装与使用
下载:
https://curl.haxx.se/download.html
安装:
二进制安装。即解压即可。
使用
1、获取页面内容。
不加任何参数时,默认会发送GET请求来获取url内容到标准输出。
curl url
D:\AppCache\GolangHome\src\learn>curl www.apple.com
#===============================================================
D:\AppCache\GolangHome\src\learn>curl www.google.com
curl: () Empty reply from server
#===============================================================
D:\AppCache\GolangHome\src\learn>curl www.xiaomi.com
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title> Moved Permanently</title></head>
<body bgcolor="white">
<center><h1> Moved Permanently</h1></center>
<hr/>Powered by MiWeb</body>
</html>
#==============================================================
D:\AppCache\GolangHome\src\learn>curl www.baidu.com
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstati
c.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true
src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f
value=> <input type=hidden name=rsv_bp value=> <input type=hidden name=rsv_idx value=> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength= autocomplete=off autofo
cus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com n
ame=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <
noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/log
in.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=b
ri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a
href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号 <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
#===================================================================
D:\AppCache\GolangHome\src\learn>
分别测试了苹果、谷歌、小米、百度。发现获得的页面内容大小相差较大。苹果啥也不给,霸道。谷歌则给了一句温馨提示语。小米则简洁地回应了一个html,重定向了。百度则回应一堆信息。
2、获取http响应的头部信息。
D:\AppCache\GolangHome\src\learn>curl -I http://www.apple.com
HTTP/1.1 Moved Permanently
Server: GHost
Content-Length:
Location: https://www.apple.com/
Cache-Control: max-age=
Expires: Sun, Sep :: GMT
Date: Sun, Sep :: GMT
Connection: keep-alive
strict-transport-security: max-age=
Set-Cookie: geo=CN; path=/; domain=.apple.com
Set-Cookie: ccl=shCgHjtuYBarTIycW/rvIg==; path=/; domain=.apple.com #===================================================================
D:\AppCache\GolangHome\src\learn>curl -I http://www.google.com
curl: () Empty reply from server
#====================================================================
D:\AppCache\GolangHome\src\learn>curl -I http://www.xiaomi.com
HTTP/1.1 Moved Permanently
Server: nginx
Date: Sun, Sep :: GMT
Content-Type: text/html
Content-Length:
Connection: close
Location: https://www.mi.com #===================================================================
D:\AppCache\GolangHome\src\learn>curl -I http://www.baidu.com
HTTP/1.1 OK
Server: bfe/1.0.8.18
Date: Sun, Sep :: GMT
Content-Type: text/html
Content-Length:
Last-Modified: Mon, Jun :: GMT
Connection: Keep-Alive
ETag: "575e1f6f-115"
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Pragma: no-cache
Accept-Ranges: bytes #==========================================================================
D:\AppCache\GolangHome\src\learn>
这次谷歌给的响应头依然是一句简短的提示语,太节约资源了。其他三个则普通给出响应头,其中苹果和小米都重定向了。
4、同时给出http的响应头和响应体。
D:\AppCache\GolangHome\src\learn>curl -i http://www.google.com
curl: () Empty reply from server
#===============================================================
D:\AppCache\GolangHome\src\learn>curl -i http://www.apple.com
HTTP/1.1 Moved Permanently
Server: GHost
Content-Length:
Location: https://www.apple.com/
Cache-Control: max-age=
Expires: Sun, Sep :: GMT
Date: Sun, Sep :: GMT
Connection: keep-alive
strict-transport-security: max-age=
Set-Cookie: geo=CN; path=/; domain=.apple.com
Set-Cookie: ccl=Pnj18CxjBB4h7LQaKIIkxg==; path=/; domain=.apple.com #=====================================================================
D:\AppCache\GolangHome\src\learn>curl -i http://www.xiaomi.com
HTTP/1.1 Moved Permanently
Server: nginx
Date: Sun, Sep :: GMT
Content-Type: text/html
Content-Length:
Connection: close
Location: https://www.mi.com <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title> Moved Permanently</title></head>
<body bgcolor="white">
<center><h1> Moved Permanently</h1></center>
<hr/>Powered by MiWeb</body>
</html>
#=============================================================
D:\AppCache\GolangHome\src\learn>curl -i http://www.baidu.com
HTTP/1.1 OK
Server: bfe/1.0.8.18
Date: Sun, Sep :: GMT
Content-Type: text/html
Content-Length:
Last-Modified: Mon, Jan :: GMT
Connection: Keep-Alive
ETag: "588604ec-94d"
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Pragma: no-cache
Set-Cookie: BDORZ=; max-age=; domain=.baidu.com; path=/
Accept-Ranges: bytes <!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstati
c.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true
src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f
value=> <input type=hidden name=rsv_bp value=> <input type=hidden name=rsv_idx value=> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength= autocomplete=off autofo
cus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com n
ame=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <
noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/log
in.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=b
ri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a
href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号 <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
#====================================================
D:\AppCache\GolangHome\src\learn>
谷歌依旧发挥着极简风格,就一句话。苹果给头不给体。小米则都给。百度则臃肿不堪。
curl下载安装与使用的更多相关文章
- curl下载安装
curl下载地址 https://curl.haxx.se/download.html 选择windows generic 下的 下载安装 安装完后解压配置系统环境变量 CURL_HOME ...
- 学了C语言,如何利用CURL写一个下载程序?—用nmake编译CURL并安装
在这一系列的前一篇文章学了C语言,如何为下载狂人写一个磁盘剩余容量监控程序?中,我们为下载狂人写了一个程序来监视磁盘的剩余容量,防止下载的东西撑爆了硬盘.可是,这两天,他又抱怨他的下载程序不好用,让我 ...
- centos shell编程5 LANMP一键安装脚本 lamp sed lnmp 变量和字符串比较不能用-eq cat > /usr/local/apache2/htdocs/index.php <<EOF重定向 shell的变量和函数命名不能有横杠 平台可以用arch命令,获取是i686还是x86_64 curl 下载 第三十九节课
centos shell编程5 LANMP一键安装脚本 lamp sed lnmp 变量和字符串比较不能用-eq cat > /usr/local/apache2/htdocs/ind ...
- Linux使用curl 方式安装docker-compose 后执行docker-compose version 检查安装是否成功时出错的解决办法
0x0.缘起: 今天在一台新的Fedora 25上按照官方文档,使用curl方式安装 docker-compose后,验证是否安装成功时出错: 安装时使用的命令为; curl -L https://g ...
- MongoDB简介以及下载安装
什么是MongoDB ? MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统.运行稳定,性能高 在高负载的情况下,添加更多的节点,可以保证服务器性能. MongoDB 旨在 ...
- windows下curl的安装和简单使用
curl是利用URL语法在命令行方式下工作的开源文件传输工具.它支持很多协议:FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以及 LDAP. 一 ...
- Linux CURL的安装
Linux CURL的安装 Linux CURL的安装 --获得安装包,从网上直接下载或者其他途径,这里直接wget# wget http://curl.haxx.se/download/cur ...
- curl的安装与使用
linux 下的curl扩展安装,记录一下(发现网上好多抄袭的也不检测一下能不能用) 1.下载curl安装包: https://curl.haxx.se/download.html 2.解压: 如 t ...
- MongoDB下载+安装+运行
一. 官网下载安装 MongoDB 提供了 OSX 平台上 64 位的安装包,你可以在官网下载安装包. 下载地址:MongoDB官网-Community Server 选择适合自己平台的版本, 下载对 ...
随机推荐
- js 实现加载百分比效果
效果: html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...
- iOS开发系列-NSURLConnection
概述 NSURLConnection是负责发送请求,建立客户端与服务端的连接.发送数据给服务器,并收集来自服务器的响应数据.其中NSURLRequest类是用来封装一个请求,包含NSURL对象.请求方 ...
- LeetCode 14.最长公共前缀(Python3)
题目: 编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower","flow& ...
- golang 高效字符串拼接
https://blog.csdn.net/u012210379/article/details/45110705 虽然方便,但是使用+=操作符并不是在一个循环中往字符串末尾追加字符串最有效的方式,一 ...
- CentOS安装tomcat并且部署Java Web项目具有一定的参考价值
本篇文章主要介绍了CentOS安装tomcat并且部署Java Web项目,具有一定的参考价值,有需要的可以了解一下.(http://m.8682222.com) 1.准备工作 b.因为tomcat的 ...
- 逻辑回归代码demo
程序所用文件:https://files.cnblogs.com/files/henuliulei/%E5%9B%9E%E5%BD%92%E5%88%86%E7%B1%BB%E6%95%B0%E6%8 ...
- springboot导入excel到mysql
@Controller @RequestMapping(path = "/excel") public class ImportController { @Autowired pr ...
- localStorage,sessionStorage,cookie区别
localStorage:HTML5新增的在浏览器端存储数据的方法.设置和获取localStorage的方法: 设置: localStorage.name = 'zjj'; 获取: localStor ...
- MyEclipse使用总结——将原有的MyEclipse中的项目转成maven项目[转]
前面一篇文章中我们了解了 在myeclipse中新建Maven框架的web项目 那么如果我们原来有一些项目现在想转成maven项目应该怎么做呢 我收集到了三种思路: 一.新建一个maven项目,把原项 ...
- 菜鸟nginx源码剖析数据结构篇(七) 哈希表 ngx_hash_t(下)[转]
菜鸟nginx源码剖析数据结构篇(七) 哈希表 ngx_hash_t(下) Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.c ...