获取POST:400角请求错误

时间:2020-03-02 07:03:43

标签: angular api postman

我正在尝试从“ http://169.38.82.132:94/token”到“ http://localhost:4200/”中获取详细信息,并收到一条消息,内容为“ POST:400角度错误的请求”。我的service.ts文件是

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 }); };
}

我已附上了从邮递员那里获取的NodeJS代码的屏幕截图。postman image

我错过任何设置了吗

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 
    });
};

但结果相同。

2 个答案:

答案 0 :(得分:0)

确保以终结点请求的指定格式对用户名和密码进行编码。

答案 1 :(得分:0)

作为一种答案,如果您要从API获取令牌,则需要在“授权”部分中传递用户ID和密码。

上面已经添加了许多有关的详细信息,请参阅上面的注释以获取更多详细信息。