title: posting x-www-form-urlencoded with javascript
body: <p>I have been searching all over the web without any result.
  I want to send a post request to a server with x-www-form-urlencoded headers.
  Here is my code:</p>
  
  <pre><code>function makeFormEncoder(hash){
    return function(key) {
      return encodeURIComponent(key) + '=' + encodeURIComponent(hash[key]);
    };
  }
  
  
  function getAccessToken() {
  // eg,
  // curl -X POST -i -H "Content-Type: application/x-www-form-urlencoded" \
  //     "https://api.usergrid.com/management/token" \
  //     -d 'grant_type=client_credentials&amp;client_id=XXXX&amp;client_secret=shhhh'
  //
  //
  // {"access_token":"BAADBEEF","expires_in":604800,"application":"uuid-here"}
  
  
    var formValues = {
          'grant_type': 'password',
          'username': appSvcs.username,
          'password': appSvcs.password
        },
        pairs = Object.keys(formValues).map(makeFormEncoder(formValues)),
        headers = {
          'Content-Type' : 'application/x-www-form-urlencoded'
        },
        url = getAppServicesUrl() + '/token',
        req = new Request(url, 'POST', headers, pairs.join('&amp;')),
        exchange = httpClient.send(req);
  }
  
  var res = getAccessToken();
  console.log(res);
  </code></pre>
  
  <p>When I run the above code I see the below error:</p>
  
  <blockquote>
    <p>functions.js:322 Uncaught ReferenceError: httpClient is not defined
        at getAccessToken (functions.js:322)
        at HTMLInputElement. (functions.js:333)
        at HTMLInputElement.dispatch (jquery-2.2.0.min.js:3)
        at HTMLInputElement.r.handle (jquery-2.2.0.min.js:3) getAccessToken @ functions.js:322 (anonymous) @ functions.js:333
    dispatch @ jquery-2.2.0.min.js:3 r.handle @ jquery-2.2.0.min.js:3</p>
  </blockquote>
  
  <p>Thank you for your time!</p>