gpt4 book ai didi

ios - 从 NSURLResponse 中提取数据

转载 作者:可可西里 更新时间:2023-11-01 05:05:53 25 4
gpt4 key购买 nike

我有一个验证用户身份的好方法,但是我不知道如何获取请求的状态代码。当我执行 NSLog(@"%@", response); 时,我可以清楚地看到它存在,但我找不到任何方法将其拉出来。有没有一种方法,还是我必须自己以某种方式解析它?

- (BOOL)authenticateUserWithEmail:(NSString *)email password:(NSString *)password
{
NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:
@"%@/users/sign_in.json?user[email]=%@&user[password]=%@&user[remember_me]=true",
LURL,
email,
password]];
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
[urlRequest setHTTPMethod:@"POST"];
NSURLResponse *response;
NSError *error;
NSData *responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
NSLog(@"Response: %@", [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding] );
NSLog(@"Response Meta: %@", response);
return (error == NULL);
}

最佳答案

试试这个

NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
NSInteger statusCode = [HTTPResponse statusCode];

关于ios - 从 NSURLResponse 中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18950763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com