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基本使用
curl保存网页-o
curl -o page.html www.sina.com

指定http访问所使用的proxy服务器及端口-x
curl -x www.sina.com

保存cookie信息:-D
curl -x ip:n -o page.html -D cookie001.txt www.sina.com

访问时添加cookie信息:-b
curl -x ip:n -o page.html -D cookie001.txt -b cookie001.txt www.sina.com