Hi @Amit Kholi_Optimus ,
Welcome to the Microsoft Q&A Platform!
It appears that the root cause of your issue lies in the automatic port suffix (:443
) being added to the URL when the .NET Core 8 Web API
is hosted in Azure App Service, but not when running locally in Visual Studio 2022.But in this case, it seems to be causing an issue by appending unnecessarily to the endpoint.
Explicitly Set URL in HttpRequestMessage:
- Ensure the
HttpRequestMessage
explicitly sets the URL without any portvar request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://testnomsapi.xyzxyz.com")); request.Headers.Host = "testnomsapi.xyzxyz.com";
- Disable Proxy in HttpClientHandler: Disable any default proxy settings in Azure by configuring
HttpClientHandler
:
var handler = new HttpClientHandler { UseProxy = false };
- Check BaseAddress in HttpClient: Ensure no unwanted port is being appended in the
BaseAddress
setting:
client.BaseAddress = new Uri("https://testnomsapi.xyzxyz.com");
- Examine App Settings in Azure: Check for any environment variables that may impact the request, such as
WEBSITE_ALT_PORT
. - Use Application Insights for Logging: Add detailed logging to track where the port is being added.
By doing this you should be able to prevent the port from being appended to your third-party API call.
If the answer is helpful, please click "Accept Answer" and kindly upvote it.