A small example of how the ASI implements the registration method (get and post)

Source: Internet
Author: User

Server-side Documentation:

Registered

/my/register.php

Input parameters:

Parameter description: Username user name password password email

Successful return value:
{
"Code": "Registered",
"Message": "Registered successfully, enter personal space"}

Registration failed:

{
"Code": "User_name_already_exists", "message": "User name already exists"

}

Imported Packages:

Get#import "ASIHttpRequest.h"//Post#import "ASIFormDataRequest.h"

Registration Method Code

-(void) Registertosns: (ID) Sender {//Http://192.168.100.1/sns/my/user_list.php?format=json Get/post//HTTP protocol PO    ST > GET nsstring *username = Usernamefield.text;    NSString *password = Passwordfield.text; NSString *email = Emailfield.text; #if 0//GET nsstring *s = [NSString stringWithFormat: @ "%@/my/register.php?us    ername=%@&password=%@&email=%@ ", qfsns_host, username, password, email];    NSLog (@ "SNS is%@", s);    Nsurl *url = [Nsurl urlwithstring:s];            ASIHTTPRequest *r = [ASIHTTPRequest requestwithurl:url]; #else//POST NSString *s = [NSString stringWithFormat:    @ "%@/my/register.php?format=xml", Qfsns_host];    http://192.168.100.1/sns/my/user_list.php Nsurl *url = [Nsurl urlwithstring:s];    Asiformdatarequest *r = [Asiformdatarequest Requestwithurl:url]; Create POST request with Asiformdatarequest also must be have setpostvalue to be the service side think is post way, no parameter Setpost:nil [r setpostvalue:username forkey:@ " Username "];   [R setpostvalue:password forkey:@ "password"]; [R setpostvalue:email forkey:@ "email"];
   [R setrequestmethod:@ "POST"];//set data acceptance mode for post

Received {"Code": "Registered", "message": "\u6ce8\u518c\u6210\u529f\u4e86\uff0c\u8fdb\u5165\u4e2a\u4eba\u7a7a\u95f4", "M_auth": "07CAUZ7QKIKUD2DLFGU3KA8DVLNEW8DSTHDHDHLJ6ATHBEZ\/LSCPVAVU8WML\/0TITVGL\/NHKXW\/JLISU6QVRLQ"} #endif r.delegate = self; R.tag = +; [R Startasynchronous];}

Generally in the browser input URL access to resources are through get mode;

In the form submission, the method can be used to specify whether a commit is a GET or post, and the default is get commit.

A URL address, which is used to describe a resource on a network, and the HTTP get,post,put,delete corresponds to this resource search, change, increase, delete 4 operations. Get is typically used to get/query resource information, and post is typically used to update resource information.

Other differences:

1. Get uses URL or cookie to pass the parameter. And the post puts the data in the body.

2. Get URLs are limited in length, then the post data can be very large.

3. Post is safer than get because the data is not visible on the address bar.

A small example of how the ASI implements the registration method (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.