Christopher Christopher - 1 year ago 325
TypeScript Question

Angular2 - Http POST request parameters

I'm trying to make a POST request but i can't get it working:

testRequest() {
var body = 'username=myusername?password=mypassword';
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');

body, {
headers: headers
.subscribe(data => {
}, error => {

I basically want to replicate this http request (not ajax) like it was originated by a html form:

URL: /api

Params: username and password

Answer Source

I think that the body isn't correct for an application/x-www-form-urlencoded content type. You could try to use this:

var body = 'username=myusername&password=mypassword';

Hope it helps you, Thierry

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download