Angular配合https-proxy-agent只有在带有尾随斜杆时才起作用-我错过了什么?
创始人
2024-10-28 19:30:10
0

这可能是由于您的API端点需要斜杠(/)而导致的问题。您可以尝试在注入HTTP Client时使用HttpClientModule的最后一个参数,该参数是一个对象,其中包含基础URI。例如:

import { NgModule } from '@angular/core';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { HttpProxyAgent } from 'https-proxy-agent';

@NgModule({
  imports: [
    HttpClientModule
  ]
})

export class MyModule {
  constructor(private http: HttpClient) {
    const httpProxy = 'http://proxyserver.com:8080';
    const agent = new HttpProxyAgent(httpProxy);

    const options = {
      // include a trailing slash if necessary
      baseUrl: 'https://api.example.com/'
    };

    this.http = new HttpClient({
      ...options,
      // include the agent to proxy requests
      httpClientBackend: {
        ...options,
        proxy: {
          agent
        }
      }
    });
  }
}

在options对象中,您可以将baseURL设置为API的基本URI,并确保它以正斜杠结尾。接下来,在构造函数中,您可以使用HttpClient的最后一个参数来配置http客户端以使用代理。

通过这种方式,您的API路径将始终以正斜杠(/)结尾,而不必手动添加它。

相关内容

热门资讯

透视好友!hhpoker德州机... 透视好友!hhpoker德州机器人,hhpoker到底可以辅助吗,攻略教程(有挂规律)-哔哩哔哩1、...
透视智能ai!wepoker破... 透视智能ai!wepoker破解器,哈糖大菠萝挂,步骤教程(有挂细节)-哔哩哔哩暗藏猫腻,小编详细说...
透视系统!aapoker脚本,... 透视系统!aapoker脚本,wepoker辅助器安装包定制,窍要教程(揭秘有挂)-哔哩哔哩1)we...
透视挂!智星德州插件,wepo... 透视挂!智星德州插件,wepoker有没有辅助,资料教程(有挂教程)-哔哩哔哩1、游戏颠覆性的策略玩...
透视苹果版!pokemmo脚本... 透视苹果版!pokemmo脚本辅助器,we poker免费辅助器,秘籍教程(有挂分享)-哔哩哔哩1、...
透视能赢!wepoker能不能... 透视能赢!wepoker能不能透视,hhpoker德州挂真的有吗,要领教程(详细教程)-哔哩哔哩1、...
透视好牌!wpk透视是真的假的... 透视好牌!wpk透视是真的假的,wepoker游戏的安装教程,教程书教程(有挂技巧)-哔哩哔哩一、w...
透视科技!wpk辅助插件,wp... 透视科技!wpk辅助插件,wpk透视插件,手册教程(证实有挂)-哔哩哔哩wpk辅助插件辅助器中分为三...
透视能赢!hhpoker辅助靠... 透视能赢!hhpoker辅助靠谱吗,wepoker怎么设置房间,手段教程(有挂技巧)-哔哩哔哩1、让...
透视好友!wpk刷入池率脚本,... 透视好友!wpk刷入池率脚本,wepoker免费透视,操作教程(有挂技巧)-哔哩哔哩wpk刷入池率脚...