title: Difference between Electron-based XMLHttpRequest and browser-based URL with query string?
body: <p>I'm working on an <code>Electron</code> app and trying to integrate the <code>Easy Digital Downloads</code> <a href="https://docs.easydigitaldownloads.com/article/384-software-licensing-api" rel="nofollow noreferrer">Software Licensing</a> WordPress plugin. I haven't done much with <code>HTTP</code> communication in Electron/Javascript so this may be a naive question.</p>
  
  <p><strong>The problem:</strong> I am able to get a license activation response from my EDD server and while there is no specific error, for some reason a license is not activated. The odd thing is that if I use a URL and query string in a browser with the same data, the plugin responds as expected: I can activate, deactivate and check the status of a license.</p>
  
  <p>So EDD seems to be working and there are no errors with Electron. But something is missing. Initially I was using the <a href="https://electronjs.org/docs/api/net" rel="nofollow noreferrer">net</a> Electron module but after this issue came up, I switched to using the <a href="https://docs.easydigitaldownloads.com/article/1038-software-licensing-api---example-using-javascript" rel="nofollow noreferrer">example script from EDD</a> (below) which uses <code>XMLHttpRequest</code>. With that I get the following response back:</p>
  
  <blockquote>
    <p>{"success":true,"license":"valid","item_id":539,"item_name":"My
    Awesome App","license_limit":1,"site_count":0,"expires":"2020-12-19
    23:59:59","activations_left":1,"checksum":"f2d66c6844b37d1fa931b813c408",
    "payment_id":248,"customer_name":"Marvin
    Gardens","customer_email":"marvin@home.com","price_id":false}</p>
  </blockquote>
  
  <p>Which is fine except that <strong>"activations_left":1</strong> never changes and it should given "license_limit":1. So something is wrong.</p>
  
  <p>On the other hand, if I use a URL with a query string in a browser, the "activations_left" is decremented and license activation only works once (as it should). For example, this works:</p>
  
  <p><code>http://YOURSITE.com/?edd_action=activate_license&amp;item_id=8&amp;license=cc22c1ec86304b36883440e2e84cddff&amp;url=http://licensedsite.com</code></p>
  
  <p><strong>My Question:</strong> is there some fundamental difference between these two methods? Is there something I need to add to my <code>XMLHttpRequest</code>? I have a support ticket open with EDD but I need to keep moving with this. And sorry to be so long-winded!</p>
  
  <hr>
  
  <p><strong>UPDATE:</strong><br>
  @aw04 suggested I try using <code>GET</code> – just tried that and I "get" the same response as before: no error but also no activation. </p>
  
  <p>Could there be some property which should (or shouldn't) be in the <code>Electron</code> request which is (or isn't) in a browser request by default?</p>
  
  <pre><code> xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
  
      if (this.readyState === XMLHttpRequest.DONE &amp;&amp; this.status === 200) {
        console.log('xhttp.responseText', xhttp.responseText);
      }
    }
  
    var url = "http://YOURSITE.com/?edd_action=activate_license&amp;item_id=8&amp;license=cc22c1ec86304b36883440e2e84cddff"
    xhttp.open("GET", url);
    xhttp.send();
  </code></pre>
  
  <hr>
  
  <pre><code>var xhttp = new XMLHttpRequest();
  var postUrl = 'http://&lt;domain.com&gt;/edd-sl/';
  
  xhttp.onreadystatechange = function() {
      if (xhttp.readyState == 4 &amp;&amp; xhttp.status == 200) {
          console.log(xhttp.responseText);
      }   
  }
  
  var data = {
      edd_action: 'check_license', 
      license:    '&lt;license key&gt;',
      item_name:  encodeURIComponent('&lt;item name&gt;'),
  };
  
  xhttp.open("POST", postUrl, true);
  xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xhttp.setRequestHeader("Access-Control-Allow-Origin", "http://local.dev");
  
  var values = '';
  for (var key in data){
      values += key + '=' + data[ key ] + '&amp;';
  }
  values = values.substring(0, values.length - 1);
  xhttp.send(values);
  </code></pre>