FastAPI running on Azure App Service returns 405 Method Not Allowed in response to POST when the App Service is set to HTTPS Only

Tom Burgess 21 Reputation points

As above, with the FastAPI app running with HTTPS Only set to false, POST requests succeed using https. As soon as I set HTTPS Only to true, a POST request to the same endpoint returns a 405 Method Not Allowed.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
5,618 questions
{count} votes

Accepted answer
  1. ajkuma 17,441 Reputation points Microsoft Employee

    To benefit the community, summarizing the answer here; from comments (above).

    HttpsOnly will only impact HTTP request (App Service Load Balancer will redirect HTTP to HTTPs).
    If the incoming is already HTTPs – then no-op. You mentioned the call is always HTTPs – so HTTPsOnly should not matter.

    From the investigations - it seems to be a combination of POSTMAN and your code issue. When you redirect /users to /users/ - it always redirect to HTTP regardless of incoming http or https. You may try to change the code when redirect /users to /users/ to preserve HTTP/HTTPS incoming scheme (http -> http, https -> https).

    @Tom Burgess

    • (mentioned in the private comment):

    thanks for the response, it has led me to the answer I required.
    I was using the prefix parameter of the APIRouter class as per It appears that this was responsible for the 307 redirect on HTTP.
    I'm still using that class but now without the prefix parameter. If I find that I require that in the future I have found this article to assist with that

    Thanks again @Tom Burgess for your patience and cooperation!

    0 comments No comments

0 additional answers

Sort by: Most helpful