_linux中curl命令详解-linux运维

linux中curl命令的使用详情:1、【curl url】获取该网址的文本信息;2、【curl -i url】获取该网址的文本信息以及协议头部信息;3、【curl -x proxy url】使用代理获取网页文本信息。

5f08bab7-de0e-eb11-8da9-e4434bdf6706.png

linux中curl命令的使用详情:

1、curl url(获取该网址的文本信息)

curl

这就是获取的信息

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="">nginx.org</a>.<br/>
Commercial support is available at
<a href="">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

2、curl -i url(获取该网址的文本信息以及协议头部信息)

这就是获取的文本信息以及协议头部信息。

HTTP/1.1 200 OK
Server: nginx/1.14.0
Date: Mon, 11 Mar 2019 02:06:55 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Mon, 29 Oct 2018 09:52:22 GMT
Connection: keep-alive
ETag: "5bd6d856-264"
Accept-Ranges: bytes
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="">nginx.org</a>.<br/>
Commercial support is available at
<a href="">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

3、curl -x proxy url(使用代理获取网页文本信息)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="" xml:lang="en">
    <head>
        <title>Test Page for the Nginx HTTP Server on Fedora</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style type="text/css">
            /*<![CDATA[*/
            body {
                background-color: #fff;
                color: #000;
                font-size: 0.9em;
                font-family: sans-serif,helvetica;
                margin: 0;
                padding: 0;
            }
            :link {
                color: #c00;
            }
            :visited {
                color: #c00;
            }
            a:hover {
                color: #f50;
            }
            h1 {
                text-align: center;
                margin: 0;
                padding: 0.6em 2em 0.4em;
                background-color: #294172;
                color: #fff;
                font-weight: normal;
                font-size: 1.75em;
                border-bottom: 2px solid #000;
            }
            h1 strong {
                font-weight: bold;
                font-size: 
            }
            h2 {
                text-align: center;
                background-color: #3C6EB4;
                font-size: 1.1em;
                font-weight: bold;
                color: #fff;
                margin: 0;
                padding: 0.5em;
                border-bottom: 2px solid #294172;
            }
            hr {
                display: none;
            }
            .content {
                padding: 1em 5em;
            }
            .alert {
                border: 2px solid #000;
            }
            img {
                border: 2px solid #fff;
                padding: 2px;
                margin: 2px;
            }
            a:hover img {
                border: 2px solid #294172;
            }
            .logos {
                margin: 1em;
                text-align: center;
            }
            /*]]>*/
        </style>
    </head>
    <body>
        <h1>Welcome to <strong>nginx</strong> on Fedora!</h1>
        <div>
            <p>This page is used to test the proper operation of the
            <strong>nginx</strong> HTTP server after it has been
            installed. If you can read this page, it means that the
            web server installed at this site is working
            properly.</p>
            <div>
                <h2>Website Administrator</h2>
                <div>
                    <p>This is the default <tt>index.html</tt> page that
                    is distributed with <strong>nginx</strong> on
                    Fedora.  It is located in
                    <tt>/usr/share/nginx/html</tt>.</p>
                    <p>You should now put your content in a location of
                    your choice and edit the <tt>root</tt> configuration
                    directive in the <strong>nginx</strong>
                    configuration file
                    <tt>/etc/nginx/nginx.conf</tt>.</p>
                </div>
            </div>
            <div>
                <a href=""><img
                    src="" 
                   
                      /></a>
                <a href=""><img 
                    src="" 
                    
                      /></a>
            </div>
        </div>
    </body>
</html>

4、curl -X POST --header"Content-Type:application/json" --data ‘{}’ url (使用post模拟json格式请求接口)

curl -X POST --header "Content-Type:application/json"  --data '{}'  
{"resultCode":"0","resultMsg":"成功","data":{"userList":[{"id":"a6fc8f27-e598-11e8-ba67-00163e14685b","name":"tom","age":"18","address":"北京1","stage":"NBA"},{"id":"24793d7c-e199-11e8-ba67-00163e14685b","name":"tom","age":"18","address":"北京3","stage":"NBA"},{"id":"247acf89-e599-11e8-ba67-00163e14685b","name":"jerry","age":"18","address":"深圳22","stage":"NBA"},{"id":"247cdafc-e599-11e8-ba67-00163e14685b","name":"james","age":"38","address":"广州d4","stage":"NBA"},{"id":"247ed96c-e599-11e8-ba67-00163e14685b","name":"curry","age":"58","address":"上海fv","stage":"NBA"},{"id":"24805b4e-e599-11e8-ba67-00163e14685b","name":"kaven","age":"78","address":"陇县","stage":"NBA"},{"id":"2481f851-e599-11e8-ba67-00163e14685b","name":"durant","age":"68","address":"富平","stage":"NBA"}]}}

POST 指定请求方式

–header 指定请求头部信息

–data 指定json请求体数据内容

5、curl -I url(仅返回请求头部信息)

curl -I .cn
HTTP/1.1 200 OK
Server: nginx/1.14.0
Date: Mon, 11 Mar 2019 03:34:29 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Mon, 29 Oct 2018 09:52:22 GMT
Connection: keep-alive
ETag: "5bd6d856-264"
Accept-Ranges: bytes

相关学习推荐:linux视频教程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值