我正在尝试使用.NET服务器,该服务器在登录时返回ASPXAUTH cookie。当我看着我与Charles的网络通信时,我肯定会重新获得cookie,但是当我检查[NSHTTPCookieStorage sharedHTTPCookieStorage]时,我发现它不包含任何东西。下面是我的代码。任何帮助将不胜感激!

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]
                                          initWithBaseURL:[NSURL URLWithString:@"http://someurl.com/api/"]];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];

NSDictionary *parameters = @{@"UserName":@"SomeUserName", @"Password":@"SomePassword"};

[manager POST:@"User/Login" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

}  failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];

最佳答案

我发现解决方案是...像这样获取cookie并设置http标头值...

[manager.requestSerializer setValue:[NSString stringWithFormat:@".ASPXAUTH=%@", cookie[@"Value"]] forHTTPHeaderField:@"Cookie"];

.NET希望以上述格式返回cookie。希望这对任何人都有帮助。

关于ios - AFNetworking ASPXAUTH Cookie AFHTTPRequestOperationManager,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21689694/

10-13 09:25