我已使用以下代码链接到 API,但没有收到响应。没有显示错误,但我从状态、错误和用户变量中得到一个空值。我已经重新检查过,我在 MainURL 变量中使用的 URL 也是正确的。
NSURL *url = [[NSURL alloc]initWithString:@"%@email=%@&password=%@&action=signin",MainURL, _EmailField.text,_PasswordField.text];
NSError *errors;
NSData *data = [NSData dataWithContentsOfURL:url];
NSDictionary *json = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&errors];
status = json[@"status"];
error = json[@"error"];
user = json[@"user"];
if ([status isEqualToString:@"success"])
{
[self performSegueWithIdentifier: @"LogIN" sender: self];
}
else
{
messages=[[NSString alloc]init];
for (int i=0; i<[error count]; i++)
{
messages=[messages stringByAppendingString:[error objectAtIndex:i]];
messages=[messages stringByAppendingString:@"\n"];
}
UIAlertView *failure=[[UIAlertView alloc]initWithTitle:@"Failure" message:messages delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
[failure show];
}