未从API Gateway中的URL调用POST方法

问题描述

我有一个基本的flask-restx应用(main.py),如下所示:

ns = Namespace(
    "greetings",description="Get Greetings."
)
parser = reqparse.RequestParser()
parser.add_argument("name",type=str,help="name")


@ns.route('/restx/hello/')
class restx_hello(Resource):
    @ns.expect(parser,validate=True)
    def get(self):
        args = parser.parse_args()
        name = args['name']
        g = 'Greetings to you!'
        return 'Hello ' + name + '! I am from restx. ' + g

    @ns.expect(parser,validate=True)
    def post(self):
        args = parser.parse_args()
        name = args['name']
        return 'This is the POST method,' + name 

代码中可以看出,我正在GET路由上同时调用POST/greetings/restx/hello/方法。我已经使用API GatewaylambdaServerless上部署了此代码

serverless.yml文件

service: flask-api

provider:
  name: aws
  runtime: python3.7

functions:
  app:
    handler: wsgi_handler.handler
    events:
      - http: ANY /
      - http: 'ANY {proxy+}'

custom:
  wsgi:
    app: app.app
    pythonBin: python3
    packRequirements: false
  pythonRequirements:
    dockerizePip: non-linux

plugins:
  - serverless-wsgi
  - serverless-python-requirements

API Gateway上,当我从仪表板分别测试GETPOST方法时,它们将打印各自的输出

GET方法的屏幕截图

enter image description here

POST方法的屏幕截图

enter image description here

我对此服务有以下URL:https://abcdefgh.execute-api.eu-central-1.amazonaws.com/dev/{proxy+}

当我通过浏览器以https://abcdefgh.execute-api.eu-central-1.amazonaws.com/dev/greetings/restx/hello/?name=Alex的形式调用URL本身时,它总是按以下方式调用GET方法

enter image description here

永远不会调用POST方法。我在做什么错?

解决方法

在浏览器上,它始终使用GET方法。

对于POST方法,可以在以下位置使用POSTMAN工具:https://www.postman.com

或在终端上使用curl

curl -X POST url