【发布时间】:2017-08-09 10:25:10
【问题描述】:
我需要使用 Angular http post 请求将用户名和密码发送到登录 api。这是我的代码:
const params = new URLSearchParams();
params.set('username', username);
params.set('password', password);
this.headers = new Headers({ 'content-type': 'application/x-www-form-urlencoded', 'authorization': 'Basic' });
this.options = new RequestOptions({headers: this.headers, method: RequestMethod.Post, params: params });
return this.http.post(this.config.baseUrlAuthSvc + this.config.login, this.options)
.map((response) => { return response; })
我收到以下错误响应:
请求网址:http://111.22.333.44:55/api/token 请求方法:选项 状态码:400 错误请求 远程地址:172.31.131.13:85 推荐人政策:降级时不推荐人
我错过了什么吗?
【问题讨论】:
-
您可能需要将请求正文设置为
username=enteredUsername&password=enteredPassword -
@jason 是的,我就是这么做的。获取请求中应使用参数