title: GeoExt PDF printing: "Error message: Origin http://localhost:55608 is not allowed by Access-Control-Allow-Origin"
body: <p>I'm trying to generate a pdf file to print a map using GeoExt but have run into a problem.  On Chrome I get the error message:</p>
  
  <pre><code>XMLHttpRequest cannot load http://Howard:8080/geoserver/pdf/create.json. Origin http://localhost:55608 is not allowed by Access-Control-Allow-Origin.
  </code></pre>
  
  <p>I think the error message tells me that its to do with the proxy so I have tried adding the following to the Config.yaml but not luck:</p>
  
  <pre><code>- !localMatch
    dummy: true
  - !ipMatch
    host: 0.0.0.0
    mask: 0.0.0.0
  </code></pre>
  
  <p>This should have allowed all local ip addresses and all hosts to access the create.json in Howard:8080 but for some reason I still get the error message.</p>
  
  <p>However, on Firefox I get a slighly different behaviour.  I dont get any error message but I end up triggering a printexception with an error message "Communication failure.</p>
  
  <p>I'm stuck and out of ideas, can anyone help?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>var printProvider =  new GeoExt.data.PrintProvider({
                //method: "GET", // "POST" recommended for production use
                method: "POST", // "POST" recommended for production use
  
                //capabilities: g_printCapabilities,  // provide url instead for lazy loading
  
                url: OpenLayers.ProxyHost + "http://Howard:8080/geoserver/pdf/",
                //url: "http://Howard:8080/geoserver/pdf/",
                autoLoad: true,
  
                customParams: {
                  mapTitle: "GeoExt Printing Demo",
                  comment: "This demo shows how to use GeoExt.PrintMapPanel with OSM"
                }
            });
  
  
  var printPage = new GeoExt.data.PrintPage({
      printProvider: printProvider
  });
  
  var mapPanel = new GeoExt.MapPanel({
      title: "Map",
      region: "center",
      height: 400,
      width: 600,
      map: map,
  
      bbar: ["-&gt;", {
          text: "Print",
          handler: function() {
              // convenient way to fit the print page to the visible map area
              printPage.fit(mapPanel, true);
  
              printProvider.print(mapPanel, printPage);
          }
      }]
  });
  
  // create a panel and add the map panel and grid panel
  // inside it
  var mainPanel = new Ext.Panel({
      renderTo: "mainpanel",
      layout: "border",
      height: 800,
      width: 600,
      items: [mapPanel]
  });
  </code></pre>
  
  <p>edit:</p>
  
  <p>I have added the following code in javascript: </p>
  
  <pre><code>var invocation = new XMLHttpRequest();  
  var url = 'http://Howard:8080/geoserver/pdf/create.json';  
  
  function callOtherDomain() {  
    if(invocation) {      
        invocation.open('POST', url, true);  
        invocation.onreadystatechange = function (){
            alert("invocation.onreadystatechange");
        }  
        invocation.send();   
    }  
  }  
  callOtherDomain(); 
  </code></pre>
  
  <p>But I still get the error message.  Do I add Access-Control-Allow-Origin header at the Howard server?  If so how do I do that?</p>
  
  <p>Edit 2:</p>
  
  <p>I have added the following in code behind:</p>
  
  <pre><code>Response.AddHeader("Access-Control-Allow-Origin", "*");
  Response.AddHeader("Access-Control-Allow-Headers", "POST");
  Response.AddHeader("Access-Control-Allow-Headers", "GET");
  </code></pre>
  
  <p>I have also placed the following:</p>
  
  <pre><code>&lt;httpProtocol&gt;
    &lt;customHeaders&gt;
      &lt;add name="Access-Control-Allow-Origin" value="*" /&gt;
    &lt;/customHeaders&gt;
  </code></pre>
  
  <p>Both code blocks added on the machine that will call the pdf file in my web.config file and still no luck.</p>
  
  <p>Edit 3.</p>
  
  <p>The pdf file seems to generate correctly if I don't include any vector layers.  That works for Firefox and chrome.  I have separate issues with IE so can't test it there.</p>