Python / Flask — server is receiving POST requests as GET requests

六眼飞鱼酱① 提交于 2021-02-10 05:00:51

问题


I created an endpoint in the flask file that looks like this

@app.route("/update", methods=['POST', 'GET'])
def update_func():
    results = {
        "method": request.method
    }
    return json.dumps(results)

I tried calling this function using both Postman and python, both are saying Flask is processing it as a get request.

import requests
r = requests.post("http://site.fakeurl.org/update", json={})
print r.json()

Is there a config file I need to change for this process as a POST request?

Is this happening to anyone else?


回答1:


Did you try using http://www.site.faekurl.org/update ?

Some servers redirect http:// to http://www.-- and as a result, the POST request + it's data gets lost in the process.



来源:https://stackoverflow.com/questions/38333689/python-flask-server-is-receiving-post-requests-as-get-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!