nginx get post 返回不同内容

    location ~* /pp {
        default_type application/json;
        if ( $request_method ~ GET){
                return 200 '{"status":"success","result":"use POST"}';
                }
        return 200 '{"status":"success","result":"success"}';
    }

使用get

# request
GET /pp HTTP/1.1
User-Agent: Fiddler
Host: 10.10.5.26
Content-Length: 0
# response
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 30 Jan 2018 07:44:20 GMT
Content-Type: application/json
Content-Length: 40
Connection: keep-alive

{"status":"success","result":"use POST"}

使用POST

# request
POST /pp HTTP/1.1
User-Agent: Fiddler
Host: 10.10.5.26
Content-Length: 0
# response
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 30 Jan 2018 07:40:06 GMT
Content-Type: application/json
Content-Length: 39
Connection: keep-alive

{"status":"success","result":"success"}

posted on 2018-01-30 15:49  mlcy  阅读(351)  评论(0)    收藏  举报

导航