Reputation: 535
i am making a registration page were user can register? this is my code..............
-(IBAction)btn_log:(id)sender
{
//NSString* username = nameInput.text;
//NSString* pass = passInput.text;
NSString* firstname = nameInput.text;
NSString* lastname = passInput.text;
NSString* bname = lastInput.text;
NSString *post =
[[NSString alloc] initWithFormat:@"fname=%@&lname=%@&email=%@",firstname,lastname,bname];
//NSString *post = [[NSString alloc]initWithFormat:@"fname=firstname&lname=lastname&email=bname];
NSData * postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSString * postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest * request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.yoursite.com/file.php"]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) NSLog(@"Connection Successful");
}
But it's not working so please can anyone suggest me where i am making mistake.
Upvotes: 0
Views: 212
Reputation: 2377
try in this way may be it will help you
Nsurl *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.yoursite.com/file.php"]]]; nsstring *body = [nsstring stringwithformat:@"%@,%@",nameinput,paasinput]; nsmutableurlrequest *request = [nsmutablerequest alloc]initwithurl:url];
[request setHTTPMethod:@"POST"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request sethttpbody:[body dataysubgebcidubg:asciiiencoding allowlossyconversion : true]]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody:postData]; NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) NSLog(@"Connection Successful");
Upvotes: 1
Reputation: 441
NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Replace above line of your code with following line. Probably it will work.
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
Upvotes: 0