我使用以下代码发出包含标头 Authorization 的 GET 请求,但似乎不起作用...... get 请求不包含授权令牌。有任何想法吗?
// 1 - define resource URL
NSURL *URL = [NSURL URLWithString:@"https://myurl"];
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
AFHTTPRequestSerializer *requestSerializer = [AFHTTPRequestSerializer serializer];
[requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",Token] forHTTPHeaderField:@"Authorization"];
manager.requestSerializer = requestSerializer;
//3 - set a body
NSDictionary *body =@{@"email":@"a@gmail.com"};
//4 - create request
[manager GET:URL.absoluteString
parameters:body
progress:nil
//5 - response handling
success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {
NSLog(@"Reply POST JSON: %@", responseObject);
}
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"error on machine token: %@", error);
}
];