title: WKWebView does not send session cookie
body: <p>I am embedding a WKWebView in my app. It uses a PHP session cookie to identify the user. I get the session cookie with the following call:</p>
  
  <pre><code>NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
  [request setHTTPMethod:@"POST"];
  [request setHTTPBody:[NSJSONSerialization dataWithJSONObject:jsonobject options:0 error:&amp;err]];
  NSHTTPURLResponse *response = nil;
  [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;err];
  </code></pre>
  
  <p>Based on this: <a href="https://stackoverflow.com/questions/26573137/can-i-set-the-cookies-to-be-used-by-a-wkwebview">Can I set the cookies to be used by a WKWebView?</a> I add the cookies to the document</p>
  
  <pre><code>for (NSHTTPCookie* cookie in [NSHTTPCookieStorage sharedHTTPCookieStorage].cookies)
  {
      NSString *javascript = [NSString stringWithFormat:@"document.cookie = '%@=%@';", [cookie name], [cookie value]];
      WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
      WKUserContentController *ucController = [[WKUserContentController alloc] init];
      WKProcessPool *processPool = [[WKProcessPool alloc] init];
      config.processPool = processPool;
      config.userContentController = ucController;
      [ucController addUserScript:[[WKUserScript  alloc] initWithSource:javascript injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO]];
  }
  </code></pre>
  
  <p>And I manually set the session cookie in the initial load request:</p>
  
  <pre><code>NSMutableURLRequest *pageLoadRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
  [pageLoadRequest setHTTPMethod:@"GET"];
  [pageLoadRequest setHTTPShouldHandleCookies:YES];
  [pageLoadRequest setAllHTTPHeaderFields:[NSHTTPCookie requestHeaderFieldsWithCookies:[NSHTTPCookieStorage sharedHTTPCookieStorage].cookies]];
  [_webView loadRequest:pageLoadRequest];
  </code></pre>
  
  <p>My problem is that AJAX requests will not contain the session cookie.</p>