We can’t see you code so we don’t know why it redirects. Typically a web api would not redirect, only return status codes.
did you change the port number when you changed the protocol?
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have an ASP.NET Core 7.0 Minimal Web API with Ocelot as API gateway. I've uploaded it to my production server and use this configuration in ocelot.json
config file:
{
"GlobalConfiguration": {
"BaseUrl": "https://api.mySite.com"
},
"Routes": [
{
"UpstreamPathTemplate": "/sync/info",
"UpstreamHttpMethod": [ "Get" ],
"DownstreamPathTemplate": "/info",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "sync.mySite.com",
"Port": 80
}
]
}
]
}
The problem is that when I send a request to the https://api.mySite.com/sync/info
URL, it redirects to https://sync.mySite.com/info
in my browser and displays the result.
First question: is this true? How to prevent to redirection when request my API via API gateway (I've also removed the line app.UseHttpsRedirection()
from program.cs
class of my API gateway project and re-published to production server, but still facing the same result)?
Second question: if I changed downstreamScheme
to https
, I am facing an http 502 (bad gateway) status code, while when I request downstream service directly via https, it works correctly. Where is the problem and how to solve it?
Thanks in advance
We can’t see you code so we don’t know why it redirects. Typically a web api would not redirect, only return status codes.
did you change the port number when you changed the protocol?
Yes, It works!!
First problem : Change port number to 443 when use https for your downstream service!
Second problem : Use app.UseHttpsRedirection() in your api gateWay project and re-publish to your server. Remember, Clear your browser cache when you call your endPoint!!!