欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Linux curl表單登錄或提交與cookie使用詳解

 更新時(shí)間:2019年08月11日 11:00:15   作者:踏歌行666  
這篇文章主要給大家介紹了關(guān)于Linux curl表單登錄或提交與cookie使用的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Linux系統(tǒng)具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

前言

本文主要講解通過(guò)curl 實(shí)現(xiàn)表單提交登錄。單獨(dú)的表單提交與表單登錄都差不多,因此就不單獨(dú)說(shuō)了。

說(shuō)明:針對(duì)curl表單提交實(shí)現(xiàn)登錄,不是所有網(wǎng)站都適用,原因是有些網(wǎng)站后臺(tái)做了限制或有其他校驗(yàn)。我們不知道這些網(wǎng)站后臺(tái)的限制或校驗(yàn)機(jī)制具體是什么,因此直接curl表單登錄可能是不行的。

當(dāng)然,如下案例是可以用curl登錄的。

案例:LeanCloud登錄

要求和結(jié)果

要求:通過(guò)curl登錄后,能正常訪問(wèn)leancloud的應(yīng)用頁(yè)面。

登錄頁(yè)面鏈接如下:

1 https://leancloud.cn/dashboard/login.html#/signin

能正常訪問(wèn)如下頁(yè)面:

1 https://leancloud.cn/dashboard/applist.html#/apps

瀏覽器訪問(wèn)效果:

無(wú)登錄直接訪問(wèn)結(jié)果瀏覽器訪問(wèn)結(jié)果

上圖紅框 403 中的訪問(wèn)連接如下:

1 https://leancloud.cn/1.1/clients/self/apps

通過(guò)curl 驗(yàn)證是否登錄

[root@iZ28xbsfvc4Z ~]# curl -i https://leancloud.cn/1.1/clients/self/apps
HTTP/1.1 403 Forbidden
Server: openresty
Date: Sun, 14 Jul 2019 11:35:28 GMT
Content-Type: application/json;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Cache-Control: no-cache,no-store
Pragma: no-cache

{"code":1,"error":"User doesn't sign in."}

獲取表單字段信息

獲取表單提交鏈接

通過(guò)下圖可得到表單提交的鏈接信息。具體如下:

1 https://leancloud.cn/1.1/signin

curl 表單登錄并保存cookie信息

1 curl -v -c leancloud1.info -X POST -F 'email=yourname' -F 'password=yourpassword' https://leancloud.cn/1.1/signin
2 # 或則
3 curl -v -c leancloud3.info -X POST -d 'email=yourname&password=yourpassword' https://leancloud.cn/1.1/signin

查看cookie信息

[root@iZ28xbsfvc4Z 20190714_02]# ll
total 32
-rw-r--r-- 1 root root 337 Jul 14 19:45 leancloud1.info
-rw-r--r-- 1 root root 335 Jul 14 19:46 leancloud3.info
[root@iZ28xbsfvc4Z 20190714_02]# cat leancloud1.info 
# Netscape HTTP Cookie File
# http://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_leancloud.cn FALSE / TRUE 1563709522 uluru_user Ff1IPOiMX%2F6ipevuxy0OOg%3D%3D
leancloud.cn FALSE / TRUE 1563709522 XSRF-TOKEN 5647dc84bd6eaea37eca2d07ae0e401cca4ba76803989c8559XXXXX7283da
[root@iZ28xbsfvc4Z 20190714_02]# cat leancloud3.info 
# Netscape HTTP Cookie File
# http://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_leancloud.cn FALSE / TRUE 1563709591 uluru_user arTwQm6JylzLjBaQt7TpiQ%3D%3D
leancloud.cn FALSE / TRUE 1563709591 XSRF-TOKEN 751e12827c7c046408541bc1bf962b5912ac35b0d07f88120XXXXXX40704704

每列字段說(shuō)明:

domain:創(chuàng)建并可以讀取變量的域名。
flag:一個(gè) TRUE/FALSE 值,表明給定域中的所有機(jī)器是否都可以訪問(wèn)該變量。此值由瀏覽器自動(dòng)設(shè)置,具體取決于你為域設(shè)置的值。
path:變量在域中有效的路徑。
secure:一個(gè) TRUE/FALSE 值,表明是否需要與域的安全連接來(lái)訪問(wèn)變量。
expiration:該變量將過(guò)期的UNIX時(shí)間。UNIX時(shí)間定義為自1970年1月1日00:00:00 GMT開(kāi)始的秒數(shù)。
name:變量名稱
value:變量值

校驗(yàn)是否登錄成功

直接訪問(wèn)和帶有cookie訪問(wèn),這兩種訪問(wèn)方式,請(qǐng)對(duì)比查看。

直接訪問(wèn)

[root@iZ28xbsfvc4Z 20190714_02]# curl -i https://leancloud.cn/1.1/clients/self/apps
HTTP/1.1 403 Forbidden
Server: openresty
Date: Sun, 14 Jul 2019 11:52:47 GMT
Content-Type: application/json;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Cache-Control: no-cache,no-store
Pragma: no-cache

{"code":1,"error":"User doesn't sign in."}

帶有cookie文件的訪問(wèn)

# 使用cookie
[root@iZ28xbsfvc4Z 20190714_02]# curl -i -b leancloud1.info https://leancloud.cn/1.1/clients/self/apps 
## 或者
[root@iZ28xbsfvc4Z 20190714_02]# curl -i -b leancloud3.info https://leancloud.cn/1.1/clients/self/apps
HTTP/1.1 200 OK
Server: openresty
Date: Sun, 14 Jul 2019 11:53:29 GMT
Content-Type: application/json;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Cache-Control: no-cache,no-store
Pragma: no-cache
Strict-Transport-Security: max-age=31536000

[{"app_domain":null,"description":null,"archive_status":0,"biz_type":"dev","master_key": ………………

復(fù)制瀏覽器的cookie訪問(wèn)

[root@iZ28xbsfvc4Z 20190720]# curl -i -H 'cookie: _ga=GA1.2.2055706705.1560005524; …………' https://leancloud.cn/1.1/clients/self/apps
HTTP/1.1 200 OK
Server: openresty
Date: Sat, 20 Jul 2019 08:11:37 GMT
Content-Type: application/json;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Cache-Control: no-cache,no-store
Pragma: no-cache
Strict-Transport-Security: max-age=31536000

[{"app_domain":null,"description":null,"archive_status":0,"biz_type":"dev","master_key": ………………

由上可知curl登錄成功。

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

  • linux userdel 命令的使用

    linux userdel 命令的使用

    這篇文章主要介紹了linux userdel 命令的使用,幫助大家更好的理解和使用Linux系統(tǒng),感興趣的朋友可以了解下
    2020-08-08
  • LNMP下提示File not found問(wèn)題的解決方法

    LNMP下提示File not found問(wèn)題的解決方法

    這篇文章主要給介紹了關(guān)于在LNMP下提示File not found問(wèn)題的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-12-12
  • linux中rz上傳、sz下載命令詳解

    linux中rz上傳、sz下載命令詳解

    這篇文章主要介紹了linux中rz上傳、sz下載命令詳解的相關(guān)資料,需要的朋友可以參考下
    2018-08-08
  • CentOS7yum安裝PHP7.2的操作方法

    CentOS7yum安裝PHP7.2的操作方法

    下面小編就為大家分享一篇CentOS7yum安裝PHP7.2的操作方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03
  • Linux實(shí)現(xiàn)文件內(nèi)容去重及求交并差集

    Linux實(shí)現(xiàn)文件內(nèi)容去重及求交并差集

    這篇文章主要介紹了Linux實(shí)現(xiàn)文件內(nèi)容去重及求交并差集,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Linux系統(tǒng)下netstat命令詳細(xì)介紹

    Linux系統(tǒng)下netstat命令詳細(xì)介紹

    大家好,本篇文章主要講的是Linux系統(tǒng)下netstat命令詳細(xì)介紹,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • linux c下log輸出代碼模板示例代碼

    linux c下log輸出代碼模板示例代碼

    這篇文章主要給大家介紹了關(guān)于在linux c下log輸出代碼模板的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-12-12
  • Apache上部署Django步驟詳細(xì)介紹

    Apache上部署Django步驟詳細(xì)介紹

    這篇文章主要介紹了Apache上部署Django步驟詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • Linux INotif機(jī)制詳解及實(shí)例代碼

    Linux INotif機(jī)制詳解及實(shí)例代碼

    這篇文章主要介紹了Linux INotif機(jī)制詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-01-01
  • Linux之路由轉(zhuǎn)發(fā)和SNAT的應(yīng)用方式

    Linux之路由轉(zhuǎn)發(fā)和SNAT的應(yīng)用方式

    這篇文章主要介紹了Linux之路由轉(zhuǎn)發(fā)和SNAT的應(yīng)用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-05-05

最新評(píng)論