我正在将数据从 iPhone 应用程序发送到服务器,但是当我提交表单应用程序崩溃时。请检查代码并建议我提前告知谢谢。
-(IBAction)SAVE:(id)sender
{
NSString *post =[[NSString alloc] initWithFormat:@"amount=50&termid=1&state=%@&city=%@&post_title=%@&description=%@&post_price=10&post_location=asd&geo_latitude=%@&geo_longitude=%@&owner_name=%@&owner_email=abc@a.a&owner_phone=%@&post_tags=a&post_url=%@&coupon_code=a¤t_userid=1&type=renew",txt4.text,txt5.text,txt6.text,latValue,longValue,txt7.text,txt8.text,txt9.text,txt10.text];
NSLog(@"String Posted:%@",post);
NSURL *url=[NSURL URLWithString:@"http://www.Example.com.mx/testing/publication.php?"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@",data);
con=[NSURLConnection connectionWithRequest:request delegate:self];
if(con){
responseData=[NSMutableData data];
}
}