Post 'x-www-form-urlencoded' content with aurelia-fetch-client

Viewed 2674

The question is simple: how do I post x-www-form-urlencoded content with Aurelia Fetch client?

I need to make the post to a simple ASP.NET Web API server that is using OWIN and Katana for authentication.

An example of what I have already tried:

var loginDTO = new FormData();
loginDTO.append('grant_type', 'password');
loginDTO.append('email', 'test');
loginDTO.append('password', 'test');

return this.http
    .fetch(config.router.token, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: loginDTO
    });

Obviously, that didn't work as intended. How is the correct way to go about posting the data presented in the example?

2 Answers

You would use FormData like this:

function sendForm() {
  var formData = new FormData();
  formData.append('email', 'test@test.com');
  formData.append('password', '123456');

  http.post(url, formData);
}
Related