Does Alamofire store the cookies automatically?

后端 未结 2 833
感动是毒
感动是毒 2021-01-31 16:13

I\'m new to Alamofire so I\'m sorry if this it\'s a noob question: this framework stores the cookies automatically?

This is because I h

2条回答
  •  盖世英雄少女心
    2021-01-31 16:32

    For those who use Moya and want to disable stored cookies make a PluginType

    (fixing the X-CSRF-Token request header is missing)

    Very basic example:

    public final class DisableCookiePlugin: PluginType {
        public init() {
    
        }
    
    public func prepare(_ request: URLRequest, target: TargetType) -> URLRequest {            
                var mutableRequest = request            
                mutableRequest.httpShouldHandleCookies = false
                return mutableRequest            
        }
    }
    

    And then use it

    MoyaProvider(
                        plugins: [
                            //NetworkLoggerPlugin(configuration: .init(logOptions: .verbose)),
                            DisableCookiePlugin()
                        ]
    

提交回复
热议问题