首页 > 解决方案 > 400 错误请求 http 调用角度

问题描述

您好我正在尝试访问此 url 以获取我的应用程序的令牌,但一直给我一个 400,我的应用程序的代理配置如下。

代理.conf:

"/token": {
      "target": {
          "host": "url",
          "protocol": "https",
          "port": 443
      },
      "secure": false,
      "changeOrigin": true,
      "logLevel":"info",
      "pathRewrite": {
          "^/token": "/auth/token"
      }
  }

这是检索令牌的函数:

private getAccessToken(): Observable<ArrayBuffer> {
    const url = '/token';
    const body = new HttpParams()
      .set('client_id', 'daiga6')
      .set('client_secret', 'aouwhyruhg8ag')
      .set('grant_type', 'client_credentials');

    const headers = new Headers({
      'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0',
      Accept: '*/*',
      'Accept-Language': 'es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3',
      'Accept-Encoding': 'gzip, deflate',
      'Content-Type': 'application/x-www-form-urlencoded',
      Connection: 'keep-alive',
      Pragma: 'no-cache',
      'Cache-Control': 'no-cache'
    });
    const options: any = {headers};
    return this.http.post(url, body, options);
  }

返回我的调用的错误消息如下:

错误请求 您的浏览器发送了此服务器无法理解的请求。原因:您对启用 SSL 的服务器端口使用纯 HTTP。请改用 HTTPS 方案访问此 URL。

有任何想法吗?

使用此配置,您可以解决它:

"/token": {
      "target": {
          "host": "url",
          "protocol": "https:",
          "port": 443
      },
      "secure": false,
      "changeOrigin": true,
      "logLevel":"info",
      "pathRewrite": {
          "^/token": "/auth/token"
      }
  }

标签: javascriptangularangular5

解决方案


推荐阅读