dongweng9474 2018-08-09 17:49
浏览 393

从Flask发送POST请求到PHP脚本

I'm trying to send a POST request to a PHP script from Flask. I am using a Datatables Editor to get information from a backend database. Datatables will send a POST request to get the data it needs when DOM is ready. However, I'm getting the following error:

Method Not Allowed The method is not allowed for the requested URL.

Here's the route:

@bp.route('/my_php', methods=['GET', 'POST'])
def php_post():
    url = 'http://localhost:5000/static/datatables-plugins/Editor-PHP-1.7.4/examples/php/staff.php'
    headers = {

        'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Encoding': 'gzip, deflate, br',
        'X-Requested-With': 'XMLHttpRequest'


    }
    data = urllib.parse.urlencode(request.form).encode('utf-8')
    resp = requests.post(url, data=data, headers=headers)
    return json.dumps(resp.content).encode('utf-8')

I think this may have to do with specifying allowed methods, however I don't know how to explicitly allow for GET/POST methods when a request for another URL is called within the Flask route.

</div>
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料