【问题标题】:AFNetworking ASPXAUTH Cookies AFHTTPRequestOperationManagerAFNetworking ASPXAUTH Cookies AFHTTPRequestOperationManager
【发布时间】:2014-02-10 22:59:42
【问题描述】:

我正在尝试使用在登录时返回 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) {

}];

【问题讨论】:

  • 你解决了这个问题吗?如何存储 cookie
  • 我刚刚发布了我发现可行的解决方案......如果您发现答案对您有用,请投票。谢谢!
  • 请检查我在堆栈上的最新问题并回答。 stackoverflow.com/questions/22078151/…

标签: ios objective-c cookies afnetworking afnetworking-2


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多