I am trying to hit this url with json parsing but when i hit with breakpoint there is no data in nslog..
在另一个解析它完美的工作,但有了这个网址它不起作用 字符串格式值为:-kk,8882121456,2015-10-26,123,123,male,02
NSString * urlLoc = @“http://www.vallesoft.com/vlcc_api/bookappointment.php”;
NSString *requestString = [NSString stringWithFormat:@"name=%@&mobileno=%@&emailid=%@&dob=%@&password=%@&gender=%@&ref=%@&fbflag=0",goSignUpName,goSignUpMobile,goSignUpEmailId,goSignUpDOB,goSignUpPassword,goSignUpGender,goSignUpReferenceId] ;
NSData *postData = [requestString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlLoc]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
if(data.length>0 && connectionError==nil)
{
responseData = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"LOGIN Response ==> %@", responseData);
if ([responseData intValue] == 1)
{
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Thanks" message:@"Registered" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
for(id controller in [self.navigationController viewControllers])
{
if([controller isKindOfClass : [ViewController class]]){ [self.navigationController popToViewController: controller animated: YES];
break;
}
}
}
else if ([responseData intValue] == 2)
{
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Already Reegistered" message:@"Please choose other Details" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
else if (responseData==NULL)
{
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Not Book Try Again!!" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
答案 0 :(得分:0)
好吧,我正在使用以下代码将其作为虚拟对象并且它可以正常工作。你可以尝试如下:
NSString *urlLoc = @"http://www.vallesoft.com/vlcc_api/bookappointment.php";
NSString *requestString = [NSString stringWithFormat:@"name=harsh&mobileno=8882121782&emailid=hkrajput12@gmail.com&date=2015-10-21&cityname=1¢rename=3&servicename=5&expertname=3×lot=15:00 TO 16:00&cuser=hkrajput12@gmail.com&cdate=2015-10-21×lotid=15"];
NSData *postData = [requestString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlLoc]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
{
if(data.length>0 && connectionError==nil)
{
NSString *responseData = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"LOGIN Response ==> %@", responseData);
}
}];