Linux curl命令

Linux curl命令,第1张

Linux curl命令 简介

curl命令用于向URL传输数据,常用于http接口测试。

支持的协议:DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP

使用方式举例
$ curl  "http://www.baidu.com" # 打印出了整个响应报文
$ curl -i "http://www.baidu.com" # 打印除了报文还有响应头信息
$ curl -I "http://www.baidu.com" # 仅返回http头信息
$ curl -v "http://www.baidu.com" # 打印更多的调试信息
$ curl -vI "http://www.baidu.com"
* Rebuilt URL to: http://www.baidu.com/
*   Trying 103.235.46.39...
* TCP_NODELAY set
* Connected to www.baidu.com (103.235.46.39) port 80 (#0)
> HEAD / HTTP/1.1
> Host: www.baidu.com
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Accept-Ranges: bytes
Accept-Ranges: bytes
< Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
< Connection: keep-alive
Connection: keep-alive
< Content-Length: 277
Content-Length: 277
< Content-Type: text/html
Content-Type: text/html
< Date: Wed, 20 Oct 2021 14:53:46 GMT
Date: Wed, 20 Oct 2021 14:53:46 GMT
< Etag: "575e1f6f-115"
Etag: "575e1f6f-115"
< Last-Modified: Mon, 13 Jun 2016 02:50:23 GMT
Last-Modified: Mon, 13 Jun 2016 02:50:23 GMT
< Pragma: no-cache
Pragma: no-cache
< Server: bfe/1.0.8.18
Server: bfe/1.0.8.18

< 
* Connection #0 to host www.baidu.com left intact

使用POST方法:

-d, --data HTTP POST data
–data-ascii HTTP POST ASCII data
–data-binary HTTP POST binary data
–data-raw HTTP POST data, ‘@’ allowed
–data-urlencode HTTP POST data url encoded
–delegation GSS-API delegation permission
–digest Use HTTP Digest Authentication

$ curl -d 'abc=def' "http://www.baidu.com" # 使⽤post⽅法提交http请求

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4001553.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-22
下一篇 2022-10-22

发表评论

登录后才能评论

评论列表(0条)

保存