ios - How to read the response headers every time using AFNetworking? -
while using 3rd party api, have requirement cancel traffic when custom response header set value. trying find nice place check once in code (and not in every success/failure block, works fine). understand, done overriding -(void)enqueuehttprequestoperation:(afhttprequestoperation *)operation
in custom afhttpclient
subclass, when implement that:
-(void)enqueuehttprequestoperation:(afhttprequestoperation *)operation { nslog(@"[request url]\n%@\n", [operation.request.url description]); nslog(@"[response headers]\n%@\n", [[operation.response allheaderfields] descriptioninstringsfileformat]); [super enqueuehttprequestoperation:operation]; }
the response headers nil
. can me that?
at moment when operations being created , enqueued in afhttpclient
, not have response server--that assigned when request operation executed.
although requirement cancel traffic seems unorthodox (at least if outside of conventions of http), easy accomplish:
in afhttpclient
subclass, add bool
property stores if requests should prevented, , used in enqueuehttprequestoperation
. then, override httprequestoperationwithrequest:success:failure:
execute specified success block along logic set aforementioned property if salient response present.
Comments
Post a Comment