What is the difference between GET and post? Send a login request using the Post method

Source: Internet
Author: User

What is the difference between GET and POST ? Use the POST method to send a login request .

{

<1> http method :

The HTTP protocol defines a number of methods that correspond to different resource operations , the most common of which are the GET and POST methods .

{

{GET,POST,OPTIONS,HEAD,PUT,DELETE,TRACE,CONNECT ,PATCH}

increased :P ut

Delete :D elete

change :P ost

Check : GET

}

<2> parameters

{

because get and post can do all of the above , in real-world development , We just use get and post method is available .

when interacting with a server , it is sometimes necessary to send some data to the server, such as the need to send a user name and password when logging in .

parameter : refers to the specific data that is passed to the server .

}

Themain differences between < 3 > GET and POST are expressed in the transfer of parameters .

"GET":

{

The essence of get is that it is more efficient to get data from the server . and a GET request can be cached .

' Note ': network cache data , saved in SQLite database ( path : Nshomedirectory ()).

To view the cache data command line :

' cd files directory ' ( Open file directory )

' ls ' to view the directory under the current file

' sqlite3 cache.db ' Open database

'. Tables ' view the forms in the database

' select * from Cfurl_cache_response; ' View server response cache

' select * from Cfurl_cache_receiver_data; ' View the data cache returned by the server

behind the request URL ? in the form of the parameters issued to the server , the parameters are "parameter name "=" argument value " in the form of splicing , multiple parameters with & separation .

Note : The length of the Get is limited , and different browsers have different length limits , typically between 2 and8K .

}

"POST":

{

The essence of POST is to send data to the server , or to get the result of the server processing , less efficient than get. POST requests cannot be cached , and the form must be resubmitted after each refresh .

the parameters sent to the server are all placed in the ' request body ' ;

in theory, there is no limit to the amount of data that POST transmits .

Note : all data related to user's privacy ( password / bank card number etc. ..) must be delivered by POST .

}

<4> Note : spaces and special symbols such as Chinese are not allowed in the URL .

1>url , All characters must be ASCII code ;

2>url cannot appear in Chinese and special symbols ( such as spaces );

therefore , if Chinese is present in the URL , you need to add a percent translation .

URLString = [URLString stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];

<5> POST Send login request :

Note :

1> with variable request : Nsmutableurlrequest *request = [Nsmutableurlrequest requestwithurl:url];

2> Specify the Request method : Requests. HttpMethod = @ "POST";

3> Set the request body Data : requests. Httpbody = data;

// Instantiate the request body string

NSString *body = [NSString stringWithFormat:@ "username=%@&password=%@",self. Username.text, Self. Password.text];

// convert string to binary data

NSData *data = [Body datausingencoding:nsutf8stringencoding];

4> send asynchronous Network requests .

[Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlresponse *response, NSData *data, Nserror *connectionerror) {

//Nsurlresponse *response: server response

//NSData *data: data returned by the server

//Nserror *connectionerror: connection error Handling

// callback for network request .

}]

}

What is the difference between GET and post? Send a login request using the Post method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.