Why a fully working web site gives a 405 error when queried using curl?

Viewed 422

I have a web app running on my LAN, and from the same subnet I can access it easily using any browser on any client with a simple http://< IP >/

Nothing special. Works all the time.

But when I try the following curl command:

curl -I http://<IP>/

I get his response from curl:

HTTP/1.1 405 Method Not Allowed
Content-Type: text/plain; charset=utf-8
Allow: GET
Content-Length: 23
Date: Fri, 21 May 2021 17:11:59 GMT
Server: Python/3.8 aiohttp/3.7.4.post0

I was expecting a 200 OK

1 Answers

You have to remove the wrong option -I which is an alias for --head, that is different from the default -X GET.

Fot that reason the response show you that HEAD method in not allowed (405), and the only accepted is GET, so you have to rewrite the command as curl http://<IP>/.


Edit*

To get only the status code, in order to test the service health, you should rewrite the command as follow:

curl -s -o /dev/null -w "%{http_code}" http://<IP>/

The result will be a string which contains the http response status code.

Related