标签:osc span ios http auto targe blog lan 创建
https://my.oschina.net/wolx/blog/406092
工程中的请求,需要设置Header,请求令牌才访问,NSURLRequest 请求没有直接设置header 的方法,需要通过NSMutableURLRequest 来实现
//1.创建request
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
//2.创建一个 NSMutableURLRequest 添加 header
NSMutableURLRequest *mutableRequest = [request mutableCopy];
NSString *value = [NSString stringWithFormat:@"Bearer %@",[BZUserTool readToken]];
[mutableRequest addValue:value forHTTPHeaderField:@"Authorization"];
//3.把值覆给request
request = [mutableRequest copy];
//4.查看请求头
NSLog(@"%@", request.allHTTPHeaderFields);
AFHTTPRequestOperationManager 设置比较简单
//1.获取一个管理者
AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
//2.得到令牌
NSString *value = [NSString stringWithFormat:@"Bearer %@",[BZUserTool readToken]];
//3.设置
[mgr.requestSerializer setValue:value forHTTPHeaderField:@"Authorization"];
标签:osc span ios http auto targe blog lan 创建
原文地址:http://www.cnblogs.com/zxykit/p/6164068.html