3

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?

2 Answers2

3

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}"
Julián
  • 1,238
  • 1
  • 12
  • 24
2

You can use

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

OR

"UpstreamPathTemplate": "/GLI/secondary/{everything}"
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77