美文网首页
AFNetworking token

AFNetworking token

作者: 227f600b867c | 来源:发表于2016-08-15 14:08 被阅读377次

    在http请求中身份验证,加token。一般加在http header里,在AFNetworking中,一般请求:

    @interface XLNetworkClient () {
        NSString *_token;
    }
    
    @property (nonatomic, strong) AFHTTPSessionManager *manager;
    
    @end
    
    @implementation XLNetworkClient
    
    + (instancetype)sharedClient {
        static XLNetworkClient *sharedClient;
        static dispatch_once_t onceToken;
    
        dispatch_once(&onceToken, ^{
            sharedClient = [[XLNetworkClient alloc] init];
            sharedClient.manager = [AFHTTPSessionManager manager];
           // 将token加到http头里
            [sharedClient.manager.requestSerializer setValue:sharedClient.token forHTTPHeaderField:@"authorization"];
        });
    
        return sharedClient;
    }
    

    相关文章

      网友评论

          本文标题:AFNetworking token

          本文链接:https://www.haomeiwen.com/subject/pieusttx.html