我正在尝试使用在登录时返回ASPXAUTH cookie的.NET服务器。当我查看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) {
}];
答案 0 :(得分:0)
我发现解决方案是......以cookie为例并设置http标头值,如此......
[manager.requestSerializer setValue:[NSString stringWithFormat:@".ASPXAUTH=%@", cookie[@"Value"]] forHTTPHeaderField:@"Cookie"];
.NET期望以上述格式返回cookie。希望这对任何人都有帮助。