Linux curl使用

安装curl

1. 下载curl包,地址https://curl.haxx.se/download/

wget https://curl.haxx.se/download/curl-7.59.0.tar.gz

2.解压缩

tar -xzvf curl-7.59.0.tar.gz

3.进入安装目录

cd curl-7.59.0

4.编译

./configure

make

make install

5.验证安装是否成功

curl --version

可以查看到版本,则curl安装成功。

可能碰到的问题

报错:error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory

解决方法:

1.查找文件地址:find -name *libcurl.so*

2.将文件路径添加到日志中:/etc/ld.so.conf

3.执行生效:/sbin/ldconfig -v

4.重新验证curl安装

curl基本使用

一、get请求
1.显示全部信息
curl -i "http://www.dangdang.com"
2.只显示头部信息
curl -I "http://www.dangdang.com"
3.显示get请求全过程解析
curl -v "http://www.dangdang.com"
4.发送HTTPS请求,忽略认证
curl -k "https://www.baidu.com"
5.通过代理发送请求,-x
curl -x "ip:port" "http://www.dangdang.com"
6.添加自定义头部,--header
curl --header "content-type:text/html" -v "http://www.dangdang.com"

7.保存网页-o

curl -o page.html www.sina.com

8.保存cookie信息:-D

curl -x ip:n -o page.html -D cookie001.txt www.sina.com

9.访问时添加cookie信息:-b

curl -x ip:n -o page.html -D cookie001.txt -b cookie001.txt www.sina.com

 二、post请求

1.添加请求data
curl -d "param1=value1" "http://www.dangdang.com"

curl -l -H "Content-type: application/json" -X POST -d '{"phone":"12345678900","password":"test"}' "http://www.test.com"

原文地址:https://www.cnblogs.com/wanwanmom/p/8890943.html