使用 AFNetworking 時,若登入後需要把 cookie 同步到重定向頁面,可先取出目前 cookie,再轉成 header fields。
BESTHttpItem *httpItem = [BESTHttpHelper sharedHelper].curHttpItem;
NSString *url = [NSString stringWithFormat:@"%@/#/login", httpItem.frontend_addr];
NSDictionary *headerFields = [NSHTTPCookie requestHeaderFieldsWithCookies:self.cookies];
[NSHTTPCookie cookiesWithResponseHeaderFields:headerFields forURL:[NSURL URLWithString:url]];
這段邏輯的重點是讓重定向 URL 能沿用目前工作階段中的 cookie 資訊。