【发布时间】:2016-01-25 06:32:34
【问题描述】:
我正在尝试在服务器上发布数据,但它无法从服务器端给出任何响应,请检查我的代码。
不给这个 url 任何值 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];
}
}
}];
}
【问题讨论】:
-
问题不在您的代码中,请检查 URL 是否有效
-
你能发布
connectionErrorlocalizedDescription吗? -
vallesoft.com/vlcc_api/… url 在我点击服务器时给出响应
标签: ios objective-c json