title: Converting JavaScript AJAX Web API query to PHP CURL
body: <p>I have a functional AJAX query against my company's <a href="http://resources.arcgis.com/en/help/server-admin-api/generateToken.html" rel="nofollow noreferrer">arcGIS's generateToken query</a> like so:</p>
  
  <pre><code>    var u = "CENTRAL\\myusername";
      var p = "myp@ssword"; 
      var payload = {
          username: u,
          password: p,
          client: 'referer',
          referer: 'https://mycompany.com/myapp',
          expiration: '60',
          format: 'json',
      };
      var tokenUrl = 'https://gis.mycompany.com/public/tokens/generateToken';
      $.ajax({
          url: tokenUrl,
          type: "POST",
          crossDomain: true,
          dataType: 'text',
          data: payload,
          success: function(data){
              token = data;
              console.log(token)
          }
      });
  </code></pre>
  
  <p>I need to rewrite this to be in my PHP backend - however, <code>curl_getinfo</code> says I have an HTTP200 but the <code>$result</code> is always </p>
  
  <blockquote>
    <p>Invalid request 
    Usage: <a href="https://gis.mycompany.com/arcgis/tokens?request=gettoken&amp;username=username&amp;password=password&amp;" rel="nofollow noreferrer">https://gis.mycompany.com/arcgis/tokens?request=gettoken&amp;username=username&amp;password=password&amp;</a>
    Usage: <a href="https://gis.mycompany.com/arcgis/tokens/generateToken?username=username&amp;password=password&amp;" rel="nofollow noreferrer">https://gis.mycompany.com/arcgis/tokens/generateToken?username=username&amp;password=password&amp;</a>
    Usage: <a href="https://gis.mycompany.com/arcgis/tokens/gettoken.html" rel="nofollow noreferrer">https://gis.mycompany.com/arcgis/tokens/gettoken.html</a></p>
  </blockquote>
  
  <p>from the endpoint. Here's my implementation:</p>
  
  <pre><code>    $GISuser = "CENTRAL\\myusername";
      $GISpassword = "myp@ssword";
      $GISurl = "https://gis.mycompany.com/public/tokens/generateToken";
      $payload = array(
          "username" =&gt; $GISuser,
          "password" =&gt; $GISpassword,
          "client" =&gt; "referer",
          "referer" =&gt; 'https://mycompany.com/myapp',
          "expiration" =&gt; "60",
          "format" =&gt; "json"
      );
  
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
      curl_setopt($curl, CURLOPT_URL, $GISurl);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  
      $result = curl_exec($curl);
      curl_close($curl);
  
      echo $result;
  </code></pre>
  
  <p>Is there a difference between AJAX and CURL web API queries that I am missing to get this to work?</p>