Getting POST : 400 Bad request in angular

Discussão em 'Angular' iniciado por Venkat, Fevereiro 13, 2025.

  1. Venkat

    Venkat Guest

    I'm trying to fetch details from "http://169.38.82.132:94/token" to "http://localhost:4200/" and am getting a message as "POST : 400 Bad request in angular". My service.ts file is

    import { Injectable } from '@angular/core';
    import { HttpClient, HttpHeaders } from '@angular/common/http';
    @Injectable({ providedIn: 'root' })
    export class PeopleService {
    constructor(private http: HttpClient) { }
    headers = new HttpHeaders({
    'method': 'POST',
    'body': 'grant_type=password&username=user&password=user',
    'Content-Type': 'text/plain'});
    fetchPeople() { return this.http.post('http://169.38.82.132:94/token', { headers: this.headers }); };
    }


    I have attached the screenshot of NodeJS code taken from postman.postman image.

    [​IMG]

    Is I missed any settings

    var data = "grant_type=password&username=user&password=user"
    headers = new HttpHeaders({
    'method': 'POST',
    //'body': 'grant_type=password&username=user&password=user',
    'Content-Type': 'text/plain'}
    );

    fetchPeople() {
    return this.http.post('http://169.38.82.132:94/token',data,{
    headers: this.headers
    });
    };


    but same results.

    Continue reading...

Compartilhe esta Página