Directly on the code:
Example: (Drag two controls in storyboard TextField, one UIButton, connect (usernametext, password, login))
@interface Viewcontroller ()
@property (nonatomic,weak) iboutlet Uitextfield *usernametext;
@property (nonatomic,weak) iboutlet Uitextfield *password;
@end
-(ibaction) login
{
[Self postLoginWithUserName:self.userNameText.text password:self.passWord.text];
}
Post Login
-(void) Postloginwithusername: (NSString *) userName Password: (NSString *) password
{
1.url
Nsurl *url = [nsurl urlwithstring:@ "/http/native ip/login.php"];
2.request
Nsmutablensurlrequest *request = [Nsmutablensurlrequest Requestwithurl:url];
The data title for the post request should be submitted with request
Request. HttpMethod = @ "POST";
Prepare a data question
NSString *bodystring = [NSString *stringwithformat:@ "username=%@&password=%@", Username,password];
Set up binary data
Request. Httpbody = [bodystring datausingencoding:nsutf8stringencoding];
3. Send the network connection to get the binary data
[Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlreponse *response,nsdata *data,nserror *connectionerror)];
NSString *result = [NSString alloc]initwithdata:data encoding:nsutf8encoding];
}
Get Login
-(void) Getloginwithusername: (NSString *) userName Password: (NSString *) password
{
1.url
NSString *urlstring = [nsstring stringwithformat:@ "/HTTP/native IP address/login.php?username =%@&password =%@", username, Password];
Percent-semicolon escape
URLString = [URLString stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];
Nsurl *url = [Nsurl urlwithstring:urlstring];
2.request
Nsurlrequest *request = [Nsurlrequest Requestwithurl:url];
3. Send the network connection to get the binary data
[Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlreponse *response,nsdata *data,nserror *connectionerror)];
NSString *result = [NSString alloc]initwithdata:data encoding:nsutf8encoding];
}
Summary:
1.
Get
HTTP//Native IP Address/login.php?username =%@&password =%@
HTTP://IP address/Log in script file? Parameter variable name = parameter value & (continuation parameter) variable name = value
Post
HTTP://IP address/Log in script
2.request
Get: There is nothing to handle, because the parameter is already specified in the URL
Post: Specify access method
HttpMethod = @ "POST";
Specifying binary data
Httpbody = binary data of the parameter string
3.NSURLConnection Asynchronous
Get is the same as post
In real-world web development, where the real change occurs, the request
iOS Development-get and Post