Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux curl form login or submission with cookie usage details

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Preface

This article focuses on the implementation of form submission login through curl. Individual form submission is similar to form login, so I don't want to talk about it separately.

Description: login for curl form submission is not applicable to all websites, because some sites have restrictions or other checks in the background. We don't know exactly what the back-end restriction or verification mechanism of these sites is, so direct curl form login may not work.

Of course, the following example can be logged in with curl.

Case: LeanCloud login

Requirements and results

Requirements: after logging in through curl, you can access the application page of leancloud normally.

The link to the login page is as follows:

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

The following pages can be accessed normally:

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

Browser access effect:

Direct access to the results browser without login

The access connection in red box 403 above is as follows:

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

Verify whether to log in through curl

[root@iZ28xbsfvc4Z ~] # curl-I https://leancloud.cn/1.1/clients/self/appsHTTP/1.1 403 ForbiddenServer: openrestyDate: Sun, 14 Jul 2019 11:35:28 GMTContent-Type: application/json;charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveVary: Accept-EncodingCache-Control: no-cache,no-storePragma: no-cache {"code": 1, "error": "User doesn't sign in."}

Get form field information

Get the form submission link

The link information for the form submission can be obtained from the following figure. The details are as follows:

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

Curl form login and save cookie information

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

View cookie information

[root@iZ28xbsfvc4Z 20190714002] # lltotal 32murRWMurray Rwhael-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 20190714002] # 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%3Dleancloud.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%3Dleancloud.cn FALSE / TRUE 1563709591 XSRF-TOKEN 751e12827c7c046408541bc1bf962b5912ac35b0d07f88120XXXXXX40704704

Field description for each column:

Domain: create and read the domain name of the variable.

Flag: a TRUE/FALSE value indicating whether all machines in a given domain can access the variable. This value is automatically set by the browser, depending on the value you set for the domain.

Path: the path where the variable is valid in the domain.

Secure: a TRUE/FALSE value indicating whether a secure connection to the domain is required to access the variable.

Expiration: the UNIX time that this variable will expire. UNIX time is defined as the number of seconds since 00:00:00 GMT on January 1, 1970.

Name: variable name

Value: variable valu

Verify whether the login is successful

Direct access and cookie access, these two access methods, please compare.

Direct access

[root@iZ28xbsfvc4Z 2019071402] # curl-I https://leancloud.cn/1.1/clients/self/appsHTTP/1.1 403 ForbiddenServer: openrestyDate: Sun, 14 Jul 2019 11:52:47 GMTContent-Type: application/json;charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveVary: Accept-EncodingCache-Control: no-cache,no-storePragma: no-cache {"code": 1, "error": "User doesn't sign in."}

Access with cookie files

# use cookie [root @ iZ28xbsfvc4Z 2019071402] # curl-I-b leancloud1.info https://leancloud.cn/1.1/clients/self/apps # # or [root@iZ28xbsfvc4Z 2019071402] # curl-I-b leancloud3.info https://leancloud.cn/1.1/clients/self/appsHTTP/1.1 200 OKServer: openrestyDate: Sun, 14 Jul 2019 11:53:29 GMTContent-Type: application/json Charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveVary: Accept-EncodingCache-Control: no-cache,no-storePragma: no-cacheStrict-Transport-Security: max-age=31536000 [{"app_domain": null, "description": null, "archive_status": 0, "biz_type": "dev", "master_key":...

Copy the cookie access of the browser

[root@iZ28xbsfvc4Z 20190720] # curl-I-H 'cookie: _ ga=GA1.2.2055706705.1560005524;. Https://leancloud.cn/1.1/clients/self/appsHTTP/1.1 200 OKServer: openrestyDate: Sat, 20 Jul 2019 08:11:37 GMTContent-Type: application/json;charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveVary: no-cache,no-storePragma: no-cacheStrict-Transport-Security: max-age=31536000 [{"app_domain": null, "description": null, "archive_status": 0, "biz_type": "dev", "master_key":...

It can be seen from the above that the curl login is successful.

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report