A
A
Abra Kadabra2018-05-27 19:15:12
Angular
Abra Kadabra, 2018-05-27 19:15:12

How to pass request parameters using url in angular 6?

The back-end fails to read the data that comes in JSON.
You need to pass them to the url.
For some reason, json still comes in, with this Content-Type:

private headers: HttpHeaders = new HttpHeaders({
        'Content-Type':  'application/x-www-form-urlencoded',
    });

    constructor(private http: HttpClient){}

    loginWithEmailAndPassword(email: string, password: string){
        return this.http.post(this.url, {email: email, password: password}, {headers: this.headers});
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-05-27
@Jmaster

const body = new HttpParams()
    .set('email', email)
    .set('password', password);

this.http.post('/login',
    body.toString(),
    {
      headers: new HttpHeaders()
        .set('Content-Type', 'application/x-www-form-urlencoded')
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question