我用过afknetwordking 2.0。错误未经授权401。我复制了我的代码和错误。你能帮我吗?请。我不理解这个问题。

NSString *token = [PMUserDefaults getAccessToken];
NSString *finalyToken = [[NSString alloc]initWithFormat:@"Bearer %@",token ];
DLog(@"LIKESAAAA %@", finalyToken);
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setValue:@"Authorization" forHTTPHeaderField:finalyToken];
[manager.requestSerializer setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];


NSDictionary *parameters = @{@"id": @"contentId"};
[manager POST:@"http://IP/Folder/api/Folder/parameter/content_like/parameter" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

"Cache-Control" = "no-cache";
    "Content-Length" = 61;
    "Content-Type" = "application/json; charset=utf-8";
    Date = "Fri, 01 Aug 2014 09:57:07 GMT";
    Expires = "-1";
    Pragma = "no-cache";
    Server = "Microsoft-IIS/8.0";
    "Www-Authenticate" = Bearer;
    "X-AspNet-Version" = "4.0.30319";
    "X-Powered-By" = "ASP.NET";
 NSLocalizedDescription=Request failed: unauthorized (401)

最佳答案

401是状态HTTP Error Unauthorized
因此,您可能在身份验证步骤中做错了什么。

您的代码可能会失败

[manager.requestSerializer setValue:@"Authorization" forHTTPHeaderField:finalyToken];

它需要看起来像
[manager.requestSerializer setValue:finalyToken forHTTPHeaderField:@"Authorization"];

试试吧

关于ios - iOS未授权的网络连接(401),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25078024/

10-13 06:32