When it comes to iOS development, almost every app uses the login feature!
In many weeks, get requests are not secure in network requests. Because he will directly expose your user name and password.
So you can only use post requests, so what's the problem? How is the post sent? Is it safe to use post?
Most of the time when people make network requests, most of them use afnetworking. So there may not be much use of the system!
This is what I wrote today, using system direct requests without using afnetworking (the three-way library uses only one mbprogresshud).
// for Speed, I use storyboard without writing code. @interface **pwd; - (ibaction) login; @end
//This piece of code is short but quite common, and is a common way for iOS to exit the keyboard.- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event{[Self.view endediting:yes];}-(ibaction) Login {//1. User nameNSString *usernametext =Self.username.text; if(Usernametext.length = =0) {[Mbprogresshud showerror:@"Please enter user name"]; return; } //2. PasswordNSString *pwdtext =Self.pwd.text; if(Pwdtext.length = =0) {[Mbprogresshud showerror:@"Please enter your password"]; return; } //Add Mask[Mbprogresshud ShowMessage:@"being desperately logged in ...."]; //3. Send the user name and password to the server (go to the HTTP protocol, because the login does not need a long connection, just send it once, with TCP too time-consuming)//Create a URL: Request path (This is my local set up a server, and sometimes in detail how to build a test server, usually if you go to the company, backstage will give you)Nsurl *url = [Nsurl urlwithstring:@"http://localhost:9090/user-summary.jsp"]; //Create a requestNsmutableurlrequest *request =[Nsmutableurlrequest Requestwithurl:url]; //5 Seconds after count request Timeout (default 60s timeout)Request.timeoutinterval =5; //The format of the request is "POST"Request. HttpMethod =@"POST"; //Encrypt the passwordPwdtext =[self md5reorder:pwdtext]; //set the request bodyNSString *param = [NSString stringWithFormat:@"username=%@&pwd=%@", Usernametext, Pwdtext]; //Set the request body (Nsstring->nsdata)Request. Httpbody =[param datausingencoding:nsutf8stringencoding]; //Set Request header information[Request SetValue:@"IPhone 6"Forhttpheaderfield:@"user-agent"]; //Send a sync request (send a request on the main thread)//Queue: Store Completionhandler this taskNsoperationqueue *queue =[Nsoperationqueue Mainqueue]; [Nsurlconnection sendasynchronousrequest:request queue:queue Completionhandler:^ (Nsurlresponse *response, NSData *data, Nserror *connectionerror) { //Hide Mask[Mbprogresshud Hidehud]; //this block will be automatically called when the request is complete. if(Connectionerror | | data = nil) {//The general request timed out will come here[Mbprogresshud ShowError:@"request failed"]; return; } //parse the JSON data returned by the serverNsdictionary *dict =[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutableleaves Error:nil]; NSString*error = dict[@"Error"]; if(Error) {[Mbprogresshud showerror:error]; } Else{nsstring*success = dict[@"Success"]; [Mbprogresshud showsuccess:success]; } }];}}
/** * MD5 ($pass. $salt) * * @param text plaintext * * @return ciphertext after encryption*/-(NSString *) Md5salt: (NSString *) text{//Sprinkle salt: Randomly insert any string into the clear textNSString *salt = [text stringbyappendingstring:@"AAA"]; return[Salt md5string];}/** * MD5 (MD5 ($pass)) * * @param text plaintext * * @return encrypted ciphertext*/-(NSString *) doubleMD5: (NSString *) text{return[[Text md5string] md5string];}/** * Encrypt First, post-order * * @param text plaintext * * @return encrypted ciphertext*/-(NSString *) Md5reorder: (NSString *) text{NSString*pwd =[text md5string]; //encrypted pwd = = 3f853778a951fd2cdf34dfd16504c5d8NSString *prefix = [pwd substringfromindex:2]; NSString*subfix = [pwd substringtoindex:2]; //post-order result = = 853778a951fd2cdf34dfd16504c5d83fNSString *result =[prefix stringbyappendingstring:subfix]; NSLog (@"\ntext=%@\npwd=%@\nresult=%@", text, pwd, result); returnresult;}
The sending user name and password for the HTTP request developed by iOS