最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

shell中的curl網(wǎng)絡(luò)請求的實現(xiàn)

 更新時間:2022年02月25日 10:57:44   作者:兵臨城下也  
本文主要介紹了shell中的curl網(wǎng)絡(luò)請求的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

shell中的curl網(wǎng)絡(luò)請求的實現(xiàn)
curl 是利用URL語法在命令行下工作的文件傳輸工具,1997年首次發(fā)行,支持文件上傳和下載,結(jié)合shell腳本體驗更棒。但按照傳統(tǒng)習(xí)慣稱 curl 為下載工具。

curl 支持的通信協(xié)議有 有FTP、FTPS、HTTP、HTTPS、TFTP、SFTP 等等,支持的平臺有 Linux、MacOSX、Darwin、Windows、DOS、FreeBSD等等。

一、curl的作用:

1、查看網(wǎng)頁源碼

denglibingdeMacBook-Pro-4: curl www.baidu.com

<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新聞</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地圖</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>視頻</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>貼吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登錄</a> </noscript> <script>document.write('<a + encodeURIComponent(window.location.href+ (window.location.search === " rel="external nofollow" " ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登錄</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多產(chǎn)品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>關(guān)于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必讀</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意見反饋</a>&nbsp;京ICP證030173號&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

// 保存整個網(wǎng)頁,使用 -o 處理
denglibingdeMacBook-Pro-4: curl -o baidu www.baidu.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2381  100  2381    0     0  77899      0 --:--:-- --:--:-- --:--:-- 79366

2、查看頭信息

denglibingdeMacBook-Pro-4: denglibing$ curl -i www.baidu.com
HTTP/1.1 200 OK
Server: bfe/1.0.8.18
Date: Mon, 03 Jul 2017 09:12:17 GMT
Content-Type: text/html
Content-Length: 2381
Last-Modified: Mon, 23 Jan 2017 13:28:11 GMT
Connection: Keep-Alive
ETag: "588604eb-94d"
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Pragma: no-cache
Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
Accept-Ranges: bytes
...
...
...

 3、發(fā)送網(wǎng)絡(luò)請求信息

GET方式請求:

curl example.com/form.cgi?data=xxx  如果這里的URL指向的是一個文件或者一幅圖都可以直接下載到本地

POST方式請求:

//數(shù)據(jù)和網(wǎng)址分開,需要使用 '--data' 或者 '-d' 參數(shù); curl默認(rèn)使用GET,使用 '-X' 參數(shù)可以支持其他動詞, 更多的參數(shù)使用 'man curl' 查看
$ curl -X POST --data "data=xxx" example.com/form.cgi

// '--user-agent' 字段,表表面客戶端的設(shè)備信息:
$ curl --user-agent "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Mobile/14F89/mideaConnect MissonWebKit/4021/zh-Hans (AppStore) (4347701760)" http://www.example.com

//使用 '--cookie' 參數(shù),可以讓curl發(fā)送cookie
$ curl --cookie "name=xxx" www.example.com

//添加頭信息,自行增加一個頭信息。'--header' 或者 '-H' 參數(shù)就可以起到這個作用
$ curl --header "Content-Type:application/json" http://example.com


//提交文件作為請求信息 使用 '@文件名' 請求
$ curl -X POST -H "Content-Type: text/xml" -d @denglibing.txt http://example.com

//denglibing.txt:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.webservices.com"><soapenv:Header/><soapenv:Body><ser:addEmpIdCardrecord><ser:empId>11622695,D58C6A25-C683-47D6-A18C-B7741284F632</ser:empId></ser:addEmpIdCardrecord></soapenv:Body></soapenv:Envelope>

二、實例

denglibingdeMacBook-Pro-4:~ denglibing$ curl https://api.github.com/users
[
  {
    "login": "mojombo",
    "id": 1,
    "avatar_url": "https://avatars3.githubusercontent.com/u/1?v=3",
    "gravatar_id": "",
    "url": "https://api.github.com/users/mojombo",
    "html_url": "https://github.com/mojombo",
    "followers_url": "https://api.github.com/users/mojombo/followers",
    "following_url": "https://api.github.com/users/mojombo/following{/other_user}",
    "gists_url": "https://api.github.com/users/mojombo/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/mojombo/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/mojombo/subscriptions",
    "organizations_url": "https://api.github.com/users/mojombo/orgs",
    "repos_url": "https://api.github.com/users/mojombo/repos",
    "events_url": "https://api.github.com/users/mojombo/events{/privacy}",
    "received_events_url": "https://api.github.com/users/mojombo/received_events",
    "type": "User",
    "site_admin": false
  }
]

當(dāng)然,既然這些請求是在命令行中執(zhí)行,完全可以寫成shell腳本,來處理一系列的工作,比如多個請求,而shell腳本在Mac中,可以使用定時任務(wù)觸發(fā),進(jìn)而完成一系列的自動化工作。

三、相關(guān)鏈接

curl網(wǎng)站開發(fā)指南

How do I POST XML data with curl

到此這篇關(guān)于shell中的curl網(wǎng)絡(luò)請求的實現(xiàn)的文章就介紹到這了,更多相關(guān)shell curl網(wǎng)絡(luò)請求內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳解如何在Linux中退出Hive命令行

    詳解如何在Linux中退出Hive命令行

    在使用Hive進(jìn)行數(shù)據(jù)查詢和操作時,有時候我們需要退出Hive命令行界面,本文將介紹如何在Linux系統(tǒng)中退出Hive命令行,文中通過代碼示例講解的非常詳細(xì),具有一定的參考價值,需要的朋友可以參考下
    2024-11-11
  • linux shell 中 2>&1的含義

    linux shell 中 2>&1的含義

    對于&1 更準(zhǔn)確的說應(yīng)該是文件描述符 1,而1 一般代表的就是STDOUT_FILENO,實際上這個操作就是一個dup2(2)調(diào)用
    2013-02-02
  • Linux中的bz2壓縮格式的實例詳解

    Linux中的bz2壓縮格式的實例詳解

    這篇文章主要介紹了Linux中的bz2壓縮格式的實例詳解的相關(guān)資料,希望通過本文大家能理解掌握這部分內(nèi)容,需要的朋友可以參考下
    2017-08-08
  • ubuntu修改terminal終端的主機名的實現(xiàn)方法

    ubuntu修改terminal終端的主機名的實現(xiàn)方法

    這篇文章主要介紹了ubuntu修改terminal終端的主機名的實現(xiàn)方法的相關(guān)資料,希望通過本文能幫助大家,需要的朋友可以參考下
    2017-08-08
  • Shell腳本從文件中逐行讀取內(nèi)容的幾種方法實例

    Shell腳本從文件中逐行讀取內(nèi)容的幾種方法實例

    今天小編就為大家分享一篇關(guān)于Shell腳本從文件中逐行讀取內(nèi)容的幾種方法實例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • linux中常用腳本和函數(shù)分享

    linux中常用腳本和函數(shù)分享

    這linux中經(jīng)常需要用到的一些腳本與函數(shù),這里簡單的分享下,方便需要的朋友
    2013-02-02
  • Shell腳本read用法實現(xiàn)

    Shell腳本read用法實現(xiàn)

    本文主要介紹了Shell腳本read用法實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • 一鍵配置CentOS iptables防火墻的Shell腳本分享

    一鍵配置CentOS iptables防火墻的Shell腳本分享

    這篇文章主要介紹了一鍵配置CentOS iptables防火墻Shell腳本分享,可保存到一個腳本文件中,在新安裝的CentOS系統(tǒng)時一條命令搞定iptables配置,需要的朋友可以參考下
    2014-07-07
  • linux?命令中的大于號、小于號的作用及代表的意思

    linux?命令中的大于號、小于號的作用及代表的意思

    在linux中,大家也許會經(jīng)常看到?<???、<<?、<<<?、>、>>?這幾個小于號、大于號,那么他們分別代表什么意思呢?下面小編通過本文給大家介紹下linux?命令中的大于號、小于號的作用,感興趣的朋友一起看看吧
    2023-01-01
  • shell腳本批量將文件復(fù)制到指定的文件夾下

    shell腳本批量將文件復(fù)制到指定的文件夾下

    本文主要介紹了shell腳本批量將文件復(fù)制到指定的文件夾下,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08

最新評論

武邑县| 黄平县| 比如县| 乾安县| 和龙市| 石嘴山市| 枞阳县| 福泉市| 彰化县| 九江县| 宜州市| 南皮县| 巨鹿县| 五原县| 平凉市| 宝坻区| 瓦房店市| 肥乡县| 民县| 攀枝花市| 塔城市| 仙居县| 沙河市| 翼城县| 晋江市| 海原县| 凯里市| 赫章县| 灵台县| 台湾省| 山东省| 福州市| 鄂温| 连州市| 子洲县| 微博| 婺源县| 孟村| 汝城县| 江都市| 峡江县|