Nsurlconnection – variable nshtturlresponse or nsurlresponse

I need to modify the response header in the nsurlresponse Is that possible?

Solution

I just talked about it with my friend My suggestion is to write a subclass of nsurlresponse These things:

@interface MyHTTPURLResponse : NSURLResponse { NSDictionary *myDict; } 
- (void)setAllHeaderFields:(NSDictionary *)dictionary;
@end

@implementation MyHTTPURLResponse
- (NSDictionary *)allHeaderFields { return myDict ?: [super allHeaderFields]; }
- (void)setAllHeaderFields:(NSDictionary *)dict  { if (myDict != dict) { [myDict release]; myDict = [dict retain]; } }
@end

If you are working on an object you have not created, you can try using object_ SetClass to call this class But I don't know if the necessary instance variables will be added If you can support a sufficiently new SDK, you can also use objc_ Setassociatedobject and put them all in one category

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>