我需要在标题中传递访问令牌来调用服务。
但我认为令牌不在标题上。我没有得到回应。我做错了什么?
代码
+(void)getUserwithToken:(NSString *)token{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://exapmle.com/api/users"]]];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"Bearer %@", token] forHTTPHeaderField:@"Authorization"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSString *str1 = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",str1);
}];
}
OutPut:connectionError:(null) ,str1:{}
答案 0 :(得分:0)
请求有几个问题: