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路径将始终以正斜杠(/)结尾,而不必手动添加它。

相关内容

热门资讯

透视教学(WePoKer)we... 透视教学(WePoKer)we-poker靠谱吗(透视)竟然是有挂(wpk教程)1、we-poker...
透视中牌率!wepokerpl... 透视中牌率!wepokerplus透视脚本免费,购买wepoker模拟器(透视)扑克教程(有挂插件)...
透视挂透视(WePoKer)w... 透视挂透视(WePoKer)wepoker辅助器免费(透视)原来是有挂(解密教程);wepoker辅...
透视教程!wepoker辅助器... 透视教程!wepoker辅助器免费,wepoker透视苹果系统(透视)可靠教程(有挂工具)1、起透看...
透视了解(wepoker)we... 透视了解(wepoker)wepoker黑侠辅助器正版下载(透视)切实是有挂(教你教程)运wepok...
透视苹果版!wepoker数据... 透视苹果版!wepoker数据分析,wepoker私人局透视插件(透视)扑克教程(有挂攻略);1、透...
透视玄学(wepoker)We... 透视玄学(wepoker)WePoKer辅助器(透视)总是有挂(透明挂教程)亲,关键说明,WePoK...
透视真的!wepoker透视底... 透视真的!wepoker透视底牌,wepoker辅助是真的吗(透视)安装教程(有挂细节);1、下载好...
透视透视(WEPOKER)淘宝... 透视透视(WEPOKER)淘宝买wepoker透视有用吗(透视)本来真的有挂(AI教程);在进入淘宝...
透视游戏!wepoker亲友圈... 透视游戏!wepoker亲友圈有用吗,wepoker私人局俱乐部怎么进(透视)技巧教程(有挂揭秘);...