小编San*_*gão的帖子

Angular HttpClient 帖子不起作用

我正在更改我的代码,将我的 http api 从 \'@angular/http\' 更改为 \'@angular/common/http\'。我的大多数请求都工作正常,但是无论我多么努力,为我带来刷新令牌的身份验证都不起作用......请看我的代码如下:

\n\n
    const headerHttp = new HttpHeaders();\n    headerHttp.set(\'Content-Type\', \'application/x-www-form-urlencoded\');\n    headerHttp.set(\'Authorization\', \'Basic YW5ndWxhcjphbmd1bGFy\');\n\n    this.clientHttp.post(this.oauthTokenUrl,\n      { username: user, password: pwd , grant_type: \'password\' },\n      {  headers: headerHttp, withCredentials: true })\n        .subscribe(\n      res => {\n         console.log(res);\n      },\n      err => {\n         console.log(\'Error occured\');\n      }\n    );\n
Run Code Online (Sandbox Code Playgroud)\n\n

但参数(用户名、密码和 grant_type )未到达服务器,并且弹出输入屏幕。

\n\n

在此输入图像描述

\n\n

这是我的请求的结果,与 \'@angular/http\' 一起工作:

\n\n

图片 1\n在此输入图像描述

\n\n

这是我的请求不起作用的结果,我在上面放置了该代码。

\n\n

图片 2\n在此输入图像描述

\n\n

编辑 1 - 身份验证输入屏幕不再弹出,代码如下。

\n\n
const _params = new HttpParams()\n.set(\'grant_type\', \'password\')\n.set(\'username\', usuario)\n.set(\'password\', senha );\n\nconst _headers …
Run Code Online (Sandbox Code Playgroud)

rest http oauth-2.0 angular

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

angular ×1

http ×1

oauth-2.0 ×1

rest ×1