Linux常用命令-curl
CURL 是一个强大的命令行工具,用于在终端中与网络资源进行交互,支持多种协议和定制选项,非常适合开发者和系统管理员进行网络调试和数据传输操作。
基本用法
- 
发送GET请求:
curl http://example.com向
http://example.com发送一个简单的 GET 请求,并输出响应内容到标准输出。 - 
保存响应到文件:
curl -o output.txt http://example.com将
http://example.com的响应保存到output.txt文件中。 - 
发送POST请求并设置请求头:
curl -X POST -H "Content-Type: application/json" -d '{"key": "value"}' http://example.com/api这会向
http://example.com发送一个 POST 请求,包含{"key": "value"}的数据体。 - 
下载文件:
curl -O http://example.com/file.zip下载
http://example.com/file.zip文件,并保存在当前目录下。 
高级用法
- HTTP方法:使用 
-X参数指定 HTTP 请求方法(GET、POST、PUT 等)。 - 身份验证:支持 
-u参数用于基本的 HTTP 身份验证。 - 使用代理:通过 
-x参数设置代理服务器。 - SSL选项:支持 
-k参数来跳过 SSL 证书验证。 - Cookie管理:使用 
-b和-c参数来发送和保存 Cookie。 
使用示例
- 
使用 Basic Auth 发送请求:
curl -u username:password http://example.com/api - 
使用代理发送请求:
curl -x proxy_server:port http://example.com - 
忽略 SSL 证书验证
curl -k -X POST -H "Content-Type: application/json" -d '{"key": "value"}' https://example.com/api/test - 
Cookie管理
# 发送请求时携带 Cookie curl -b "session_id=abcdef1234567890" http://example.com/protected/resource # 保存服务器返回的 Cookie 到文件 curl -c cookies.txt http://example.com/login # 同时发送和保存 Cookie curl -b "session_id=abcdef1234567890" -c cookies.txt http://example.com/protected/resource 

                
            
        
浙公网安备 33010602011771号