title: set cookies for different domains
body: <p>I have two domains: sharepoint.server.com   AND   app.server.com</p>
  
  <p>In the application from domain app.server.com I do invisible ntlm authentication on the server sharepoint.server.com.</p>
  
  <p>sharepoint.server.com returns me its cookies. How is it possible to write these cookies to the browser's memory?</p>
  
  <p>It's possible to write these cookies, but just with domain app.server.com, but I need to write it with domain sharepoint.server.com. </p>
  
  <p>So, if it's written to the browser's memory, sharepoint.server.com will never show authentication user window again based on the existing cookies. However, it cannot read these cookies, because it's different domain.</p>
  
  <pre><code>DefaultHttpClient httpClient = new DefaultHttpClient(cm,params);
  httpClient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
  httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY),
  new NTCredentials("login", "pass", null, "server.net"));
  HttpGet httpget = new HttpGet("htts://sharepoint.server.com/");
  HttpResponse response;
  try {
       response = httpClient.execute(httpget);
       StatusLine entity = response.getStatusLine();
       System.out.println("executing request " + httpget.getRequestLine());
       System.out.println(entity.toString());
       System.out.println("");
  Header[] headers = response.getAllHeaders();
  for (Header header : headers) {
        System.out.println(header.getName() + " : " + header.getValue());
  }
  List&lt;Cookie&gt; cookies = httpClient.getCookieStore.getCookies();
  for(Cookie cookie:cookies)
  {
  JavaApp.getInstance().getMainWindow().executeJavaScript(
  "document.cookie='" + cookie.getName()+"="+cookie.getValue() +"; domain="+cookie.getDomain()+"; path="+cookie.getPath()+"'");
  }
  </code></pre>
  
  <p>Now it doesnt write cookies at all, because cookie.getDomain()=sharepoint.server.com, and it cannot be written.</p>
  
  <p>If I remove domain=cookie.getDomain() from the line, it writes cookies to the momory, but uses domain domain "app.server.com"</p>
  
  <p>But I need to write these cookies with domain sharepoint.server.com</p>
  
  <p>How is it possible to make it?</p>