1. What problem does this article solve and what can we learn? I am working on a hospital affairs system project recently, so I will record the process of learning new knowledge. This article is about the login operation. I originally thought that the login process was a relatively simple thing, but after a deeper understanding, it is still difficult: 1. To obtain the verification code photo during the login process, use the HTTP get operation. To pass the parameters to the server, you need to use post. 2. The above get and post operations can be implemented using many current network frameworks, such as volley, but after obtaining the verification code photo, a session must be maintained. Therefore, after consulting the information, it is more convenient and quick to use the okhttp framework to build this project. Let's first learn how to use okhttp: http://blog.csdn.net/itachi85/article/details/51190687 There is also a quick start to load photos using okhttp: http://blog.csdn.net/bo543937071/article/details/53380651 2. Q: What are sessions and cookies? Simply put, cookie is the session ID of the client, and session is the session ID of the server. Based on this ID number, you can query the content of your session. (To learn more about cookies and sessions, click here) http://blog.csdn.net/androidxiaogang/article/details/51925388 In this project, we need to obtain the verification code photo. Because each time you refresh the verification code URL, a different verification code photo will appear, so you need to save the verification code session, otherwise how can others know which verification code you have a "session" with. First, the photo: As shown in the figure, it is divided into four steps, which is easier to understand with text: 1. The client sends a request for a verification code photo, and brings back the photo and a jsessionid field that is stored in the user's cookie. 2. We take out the session from the cookie header, and then pack the parameters and send it along with the session so that the server knows who sent it. The four steps and two points of summary make it easier to understand with the code. 3. Analyze some important codes and then paste all the codes Let's take a look at the data given to us by the backend. There is url_randCodeImage used to send a get request to obtain photos, and url_login used to post data. These are the data we want to package and send: And our xml interface First, we get our verification code photo and load the picture asynchronously
After getting the photos and session, we package and send the data:
***Let's take a look at the information logged out after we successfully logged in *** Here is our full code, I hope it will be helpful to those who don’t understand the process: Continue |
<<: Building iOS Routers Step by Step
>>: iOS Developer Account Summary
01. How can I rank at the top of search results? ...
On a calm night, a gentle breeze blew quietly ove...
Toyota is a national brand of Japan and a world-r...
If you encounter food choking, don't try any ...
Produced by: Science Popularization China Author:...
This article will focus on the "universal fo...
There are a wide variety of products today, and t...
Like any startup, we are experimenting to find th...
For information flow advertising , the content an...
If you are a Nexus device user who is constantly ...
Dinosaurs are definitely the stars of ancient cre...
I once saw a passage, "All marketing is mark...
When a company does online network promotion, whe...
The case analysis brought is the marketing promot...
In the golden autumn of October, in addition to t...