Ocelot Gateway 重复查询参数

发布于 2025-01-09 18:31:14 字数 988 浏览 4 评论 0原文

我正在使用 ocelot 网关。

这是示例配置

{
  "DownstreamPathTemplate": "/ipgeo?apiKey={key}&ip={ip}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "api.ipgeolocation.io",
      "Port": 80
    }
  ],
  "UpstreamHttpMethod": ["GET"],
  "UpstreamPathTemplate": "/GLI/secondary?apiKey={key}&ip={ip}"
}

如您所见,有两个查询参数。当我使用 postman: OCELOT 发送请求时,

http://localhost:5000/GLI/secondary?apiKey=aaa&ip=8.8.8.8

会获取重复的查询参数并生成如下下游 url:

 http://api.ipgeolocation.io/ipgeo?apiKey=aaa&ip=8.8.8.8&apiKey=aaa&ip=8.8.8.8

控制台屏幕:

info: Ocelot.Requester.Middleware.HttpRequesterMiddleware[0]
  requestId: 0HMFNFVDSDQH9:0000000A, previousRequestId: no previous request id, message: 301 (Moved Permanently) status code, request uri: http://api.ipgeolocation.io/ipgeo?apiKey=aaa&ip=8.8.8.8&apiKey=aaa&ip=8.8.8.8

如何更改此设置?

I am using ocelot gateway.

Here is the example configuration

{
  "DownstreamPathTemplate": "/ipgeo?apiKey={key}&ip={ip}",
  "DownstreamScheme": "http",
  "DownstreamHostAndPorts": [
    {
      "Host": "api.ipgeolocation.io",
      "Port": 80
    }
  ],
  "UpstreamHttpMethod": ["GET"],
  "UpstreamPathTemplate": "/GLI/secondary?apiKey={key}&ip={ip}"
}

As you can see, there are two query params. When I send a request using postman:

http://localhost:5000/GLI/secondary?apiKey=aaa&ip=8.8.8.8

OCELOT get duplicate query params and generate a downstream url like this:

 http://api.ipgeolocation.io/ipgeo?apiKey=aaa&ip=8.8.8.8&apiKey=aaa&ip=8.8.8.8

Console screen:

info: Ocelot.Requester.Middleware.HttpRequesterMiddleware[0]
  requestId: 0HMFNFVDSDQH9:0000000A, previousRequestId: no previous request id, message: 301 (Moved Permanently) status code, request uri: http://api.ipgeolocation.io/ipgeo?apiKey=aaa&ip=8.8.8.8&apiKey=aaa&ip=8.8.8.8

How can I change this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

硪扪都還晓 2025-01-16 18:31:14

同样的问题,

对于我的作品使用这种语法,基本上我已经删除了“?” UpstreamPathTemplate 中的符号:

"DownstreamPathTemplate": "/GLI/secondary?{everything}"

"UpstreamPathTemplate": "/GLI/secondary{everything}"

Same problem,

For me works use this syntax, basically I have removed the "?" symbol in the UpstreamPathTemplate:

"DownstreamPathTemplate": "/GLI/secondary?{everything}"

"UpstreamPathTemplate": "/GLI/secondary{everything}"
爱,才寂寞 2025-01-16 18:31:14

您可以使用

"DownstreamPathTemplate": "/ipgeo?{everything}"
"UpstreamPathTemplate": "/GLI/secondary?{everything}"

"UpstreamPathTemplate": "/GLI/secondary/{everything}"

You can use

"DownstreamPathTemplate": "/ipgeo?{everything}"
"UpstreamPathTemplate": "/GLI/secondary?{everything}"

OR

"UpstreamPathTemplate": "/GLI/secondary/{everything}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文