Tuesday, 21 February 2012

Adding data to a sever with the data and the URL seperately in the POST method.

NSString *post =[[NSString alloc] initWithFormat:@"account_type=%@&user_id=%@&user_name=%@&comment_text=%@&post_id=%@",type,[acct username],[acct accountDescription],item.text,commentID];
                       
                        NSURL *url=[NSURL URLWithString:@"http://iphone.jiujitsucoach.com/index.php?action=newcomment"];
                       
                        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
                       
                        NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
                       
                        NSMutableURLRequest *request1 = [[[NSMutableURLRequest alloc] init] autorelease];
                        [request1 setURL:url];
                        [request1 setHTTPMethod:@"POST"];
                        [request1 setValue:postLength forHTTPHeaderField:@"Content-Length"];
                        [request1 setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
                        [request1 setHTTPBody:postData];
                       
                       
                        [NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
                       
                        NSError *error;
                        NSURLResponse *response;
                        NSData *urlData=[NSURLConnection sendSynchronousRequest:request1 returningResponse:&response error:&error];
                       
                        NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
                        NSLog(@"here...%@",data);

No comments:

Post a Comment