Why can't I get the correct HTTP request method

38 views
Skip to first unread message

XU LIU

unread,
Aug 10, 2023, 8:03:47 AM8/10/23
to cherrypy-users
I made a demo, but there are two questions:

1. Whether the HTTP request method is GET or POST, all I get is GET, why?
2. Why is the status code of the http response 301

demo
import cherrypy


class Hello:
    @cherrypy.expose
    def index(self):
        print(cherrypy.request.method)
        return 'hello'


class App:

    def __init__(self):
        self.hello = Hello()

    @cherrypy.expose
    def index(self):
        return 'index'


cherrypy.quickstart(App(), '/api')



log
127.0.0.1 - - [09/Aug/2023:14:51:06] "GET /api/hello HTTP/1.1" 301 119 "" "PostmanRuntime/7.32.3"
GET
127.0.0.1 - - [09/Aug/2023:14:51:07] "GET /api/hello/ HTTP/1.1" 200 5 "http://127.0.0.1:9999/api/hello" "PostmanRuntime/7.32.3"


127.0.0.1 - - [09/Aug/2023:14:51:14] "POST /api/hello HTTP/1.1" 301 119 "" "PostmanRuntime/7.32.3"
GET
127.0.0.1 - - [09/Aug/2023:14:51:14] "GET /api/hello/ HTTP/1.1" 200 5 "http://127.0.0.1:9999/api/hello" "PostmanRuntime/7.32.3"

Sviatoslav Sydorenko

unread,
Aug 10, 2023, 10:06:43 AM8/10/23
to cherryp...@googlegroups.com
1. How do you know you actually send POST requests? It might be that you're misusing the client.
2. As for the redirect, it happens because your request was lacking a trailing slash.

--Sviatoslav.

Sent from my phone, please pardon any typos.

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cherrypy-users/e58bf17a-f76c-47dd-b84e-ee3eee507c68n%40googlegroups.com.

XU LIU

unread,
Aug 13, 2023, 9:46:47 PM8/13/23
to cherrypy-users
@Sviatoslav Sydorenko

Thank you. 
I found the cause of the first problem. Lacking a trialing slash, the redirect happen, which caused all I got is GET. 
Reply all
Reply to author
Forward
0 new messages