Comparison of Get and post

Source: Internet
Author: User

GET Login
- (void) GetLogin {NSString *urlstring = [NSString stringWithFormat:@ "http://localhost/login.php?username=%@&password=%@",Self. Username,Self. pwd];Nsurl *url = [Nsurl Urlwithstring:urlstring];nsurlrequest *request = [nsurlrequest RequestWithURL:url Cachepolicy:nsurlrequestreturncachedatadontload timeoutinterval:10.0]; //default is the GET method, no need to specifically specify nslog (@ "%@" , Requestnsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue MainQueue] completionhandler:^ (Nsurlresponse *response, nsdata *data, nserror *connectionerror) {id result = [nsjsonserialization jsonobjectwithdata:data options: 0 error:null]; nslog (@ "%@-%@", response, result);}];}    
Basic format for URLs
    • Logon script: login.php , hint: in different companies using the background interface is not the same jsp , aspx ...
    • If you want to take parameters, use the ? join
    • Parameter format:参数名=值
    • If there are multiple parameters, use the & connection
GET Cache
    • The get cache data is saved in the cache directory under \bundleid Cache.db
      • cfurl_cache_receiver_data, all request data is cached
      • cfurl_cache_response, all responses are cached

The above operation is only for demonstration, the content will be explained in follow-up SQLite

POST Login
- (void) Postlogin {Nsurl *url = [Nsurl URLWithString:@ "http://localhost/login.php"];    Nsmutableurlrequest *request = [Nsmutableurlrequest Requestwithurl:url]; Request. HttpMethod =@ "POsT";NSString *BODYSTR = [nsstring stringWithFormat:@ "username=%@&password=%@", self. Username, self. pwd]; Request. Httpbody = [Bodystr datausingencoding:nsutf8stringencoding]; [nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlresponse *response, nsdata *data, nserror *connectionerror) { id result = [nsjsonserialization JSONObje Ctwithdata:data options:0 Error:NULL]; NSLog (@ "%@-%@", response, result);}];}             
GET & POST Compare URLs
    • GET-Real changes are in the URL

      • URL format
        • Login.php is responsible for login script (hint, server script can have many kinds, PHP is used in class)
        • If the parameter is connected, use the?
        • parameter format, value pairs:参数名=值
        • Multiple parameters, using the & connection
        • If you URL have special characters such as Chinese/white space in the string, you need to add percent escape
          [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    • POST

      • URLDoes not contain any parameters, you can specify the script path directly
Request
    • Get-is the most frequently used method of network access, the default way to get data from the server URLRequest isGET

      • No need to make any changes
    • POST

      • You need to specify an access method for HTTP:POST
      • All data parameters are specified in the data body, and the data contents can be Firebug pasted from the
      • GETthe parameter definitions for data formats and methods are very similar, without?
Connection
    • will be sent to the 请求 server
    • Returns the binary data entity of the server
    • Is the most simple method in network access.
    • GET POST No change, no matter how it is Connection

Comparison of Get and post

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.