title: Firefox addon sdk Request module POST method with payload
body: <p>I need to do a POST method inside a firefox add-on to another server, I have been trying to use different ways, and after googling I found out that I should use the Request module from the SDK inside my main.js. </p>
  
  <p>I am using firefox v 23</p>
  
  <p>I tried using the chrome module </p>
  
  <pre><code>var xmlhttp = chrome.Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
                          .createInstance(chrome.Ci.nsIXMLHttpRequest);
  </code></pre>
  
  <p>but I got <strong>NS_ERROR_FAILURE</strong>. I even added the permissions in the package.json</p>
  
  <pre><code>"permissions": {
      "cross-domain-content": ["https:[some url]"]
    }
  </code></pre>
  
  <p>But it still gives the same error.</p>
  
  <p>I then used the Request module but didn't work so far. I tried a GET method with the Request module and it works fine. But the POST method always returns a <strong>0</strong> status and an empty response.</p>
  
  <p>I tried doing the same request via a browser http client and it worked fine!! But through the code inside the add-on it always returns a 0.</p>
  
  <p>The request sets headers and of course has a payload. </p>
  
  <pre><code>var contentObject = {[Valid JSON Object]};
  
  var myRequest = Request({
      url: "https://[some url]",
      headers: {
             "pragma": "no-cache"
      },
      content: contentObject,
      contentType: "application/json", 
      onComplete: function (response) {
          console.log("Status: " + response.status);
          console.log("Response json: " + JSON.stringify(response));
      }
      }).post(); 
  </code></pre>
  
  <p>Your support is highly appreciated. There are very few resources I found over the internet about this issue and non of them solved my problem.</p>