cookie redirection code in iOS AFNetworking

  • 2020-12-19 21:13:23
  • OfStack


// 1.  Take out the ones that need to be synchronized url ( The redirected address returned in the login request )
BESTHttpItem *httpItem = [BESTHttpHelper sharedHelper].curHttpItem;
NSString *url = [NSString stringWithFormat:@"%@/#/login", httpItem.frontend_addr];
// 2.  Take out the current headerFields
NSDictionary *headerFields = [NSHTTPCookie requestHeaderFieldsWithCookies:self.cookies];
// 3.  replace cookie address 
[NSHTTPCookie cookiesWithResponseHeaderFields:headerFields forURL:[NSURL URLWithString:url]];

Related articles: