Post request to send user information to the server

Source: Internet
Author: User

#define Kregist @ "Http://api.sucar.com.cn/mobile/index.php?app=mobile&controller=member&action=register"

#define Kland @ "Http://api.sucar.com.cn/mobile/index.php?app=mobile&controller=member&action=login"

@property (Nonatomic,strong) Uitextfield *username;

@property (Nonatomic,strong) Uitextfield *password;

@property (Nonatomic,strong) Uitextfield *email;

-(void) regist

{

Nsmutableurlrequest *request=[nsmutableurlrequest Requestwithurl:[nsurl urlwithstring:kregist];

Set Request type

[Request sethttpmethod:@ "POST"];

NSString * body=[nsstring stringwithformat:@ "username=%@&password=%@&email=%@", Self.userName.text, Self.password.text,self.email.text];

NSData *data=[body datausingencoding:nsutf8stringencoding];

Set the package body

[Request Sethttpbody:data];

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

Nsdictionary *dict=[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers Error:nil];

NSString *result=dict[@ "message"];

NSString *s=dict[@ "state"];

Nsinteger State=[s IntegerValue];

if (state==0) {

Uialertview *wrong=[[uialertview alloc] initwithtitle:@ "Warning" message:result delegate:self cancelbuttontitle:@ "OK" Otherbuttontitles:nil];

[Wrong show];

}else if (state==1)

{

Uialertview *right =[[uialertview alloc] Initwithtitle:nil message:@ "registered successfully" Delegate:self cancelbuttontitle:@ "OK" Otherbuttontitles:nil];

[Right show];

}

}];

}

Post request to send user information to the server

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.