Mutable NSHTTPURLResponse or NSURLResponse

后端 未结 4 1675
一生所求
一生所求 2021-01-14 09:44

I need to modify response headers in an NSURLResponse. Is this possible?

4条回答
  •  孤城傲影
    2021-01-14 10:22

    You can read them into a NSDictionary using the allHeaderFields method.

        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
        NSDictionary *httpResponseHeaderFields = [httpResponse
    allHeaderFields];
    

    To be 100% safe you'd want to wrap it with

    if ([response respondsToSelector:@selector(allHeaderFields)]) {... }
    

提交回复
热议问题