gpt4 book ai didi

ios - AFNetworking - AFHTTPRequestOperationManager 不返回数据

转载 作者:行者123 更新时间:2023-11-29 12:30:03 25 4
gpt4 key购买 nike

我正在使用 AFHTTPRequestOperationManager 进行登录。

- (IBAction)loginAction
{
[TGProjectHandler clearCookies];

NSDictionary *params = @{@"Email": _email.text,
@"Password": _password.text,
@"IsRemember": @"true",
@"ReturnUrl": @"",
@"UserId": @0,
@"OutResponse": @0};

[_sharedHandler.requestManager POST:TGURL_LOGIN
parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {

NSError *e;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:[operation.responseString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&e];
NSLog(@"%@\n\n%@", jsonDict, responseObject);
NSString *outResponse = responseObject[@"Object"][@"OutResponse"];
if (outResponse.integerValue == 1){
NSLog(@"login successful: %@", outResponse);
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"User_Logged_In"];
[TGProjectHandler saveCookiesToDefaults];
[self performSegueWithIdentifier:@"HomePage" sender:self];
}else
{
[[[UIAlertView alloc] initWithTitle:@"Login Failed" message:@"Invalid credentials" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[TGProjectHandler dismissHUD];
[[[UIAlertView alloc] initWithTitle:@"Login Failed" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}];
}

服务函数返回 UserID,但这是我在 NSLog 时得到的响应。

NSLog(@"%@\n\n%@", jsonDict, responseObject); 



Object = {
OutResponse = 1;
ReturnUrl = "<null>";
};
Success = 1;
}

{
Object = {
OutResponse = 1;
ReturnUrl = "<null>";
};
Success = 1;
}

为什么 UserId 没有响应?

最佳答案

通过查看您的代码,我猜问题可能出在您请求中的内容类型上。检查您的内容类型是否设置正确。

例如-

[_sharedHandler.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

您还可以将响应序列化器更改为 AFJSONResponseSerializer,它会自动将您的响应转换为字典或数组。

_sharedHandler.responseSerializer = [AFJSONResponseSerializer serializer];

关于ios - AFNetworking - AFHTTPRequestOperationManager 不返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27979304/

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