首页 > 其他分享 >Flask - How do I read the raw body in a POST request when the content type is "application/x-ww

Flask - How do I read the raw body in a POST request when the content type is "application/x-ww

时间:2024-04-07 16:37:35浏览次数:18  
标签:body do www form Flask type request content data

Turns out that Flask sets request.data to an empty string if the content type of the request is application/x-www-form-urlencoded. Since I'm using a JSON body request, I just want to parse the json or force Flask to parse it and return request.json.

This is needed because changing the AJAX content type forces an HTTP OPTION request, which complicates the back-end.

How do I make Flask return the raw data in the request object?

 

 

You can get it that way:

@app.route("/path-to-the-post-endpoint", methods=["POST"])
def handle_post_request():
    data = request.form.to_dict()
    data['some_key_1'] = "Some Value 1"
    data['some_key_2'] = "Some Value 2"
    # ...etc.

    # DO SOMETHING HERE

    return [], 200

  

标签:body,do,www,form,Flask,type,request,content,data
From: https://www.cnblogs.com/weifeng1463/p/18119327

相关文章

  • class path resource [applicationContext.xml] cannot be opened because it does no
    测试运行报错:无法打开applicationContext.xml解决方法:打开File->ProjectStructure...找到Moudles->path->OutPutPath中写入resources路径......
  • windows服务器间文件同步--Syncthing
    一、说明:Syncthing免费且开源,跨平台支持Windows、Mac、Linux、Android等主流平台,除了PC、手机以外,在部分路由器、树莓派等硬件上都能轻松运行,它将以网页版的形式呈现,并且Syncthing还提供了中文界面的支持。二、下载官网下载地址:https://syncthing.net/downloads/按照自......
  • Do not nest ternary expressions no-nested-ternary 这个报错什么意思
    ESLint规则no-nested-ternary当检测到代码中存在嵌套的三元表达式时,会发出警告或错误。该规则旨在通过禁止使用嵌套的三元表达式来提升代码的可读性和可维护性,因为随着条件复杂度的增加,深度嵌套的三元表达式往往会变得难以理解和推理。三元表达式:三元表达式是JavaScript中一......
  • windows的一个socket 客户端程序
    windows的一个socket客户端程序#include<iostream>#include<WinSock2.h>#include<WS2tcpip.h>#include<chrono>#include<thread>//链接库#pragmacomment(lib,"Ws2_32.lib")intmain(){//初始化WinsockWSADATAwsa......
  • docker-compose 安装nginx
    docker-compose.yamlversion:'3.3'services:nginx:image:nginxrestart:alwayshostname:nginxcontainer_name:nginxprivileged:trueports:-80:80-443:443volumes:-./nginx/conf/:/etc/nginx/......
  • 【办公类-48-02】20240407每月电子屏台账汇总成docx-2(腾讯文档xlsx导入docx,每页20条)
    作品展示背景需求:安全主任再次催交台账一分园老师发的是链接版——这是我原来制作的在线共享填写“腾讯文档”。但是感觉手机竖版填写起来不方便,(表格是横版的,要向右滑动点击格子,填起来容易错行),所以我推荐使用问卷星填写了。腾讯文档里面是选择按钮填入信息,也是所有数据......
  • 基于新版宝塔Docker部署在线客服系统过程小记
    我在业余时间开发维护了一款免费开源的升讯威在线客服系统,也收获了许多用户。对我来说,只要能获得用户的认可,就是我最大的动力。客服系统开发过程中,最让我意外的是对TCP/IP协议的认识。过去一直认为TCP/IP是可靠的连接,加上过去开发的软件网络环境比较稳定,很少在这个问题上纠结......
  • 学习hadoop的第三天——hive搭建
    学习hadoop的第三天hive介绍hive的基本信息Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供简单的SQL查询功能,可以将SQL语句转换为MapReduce任务进行运行。其优点是学习成本低,可以通过类SQL语句快速实现简单的MapReduce统计,不必开发......
  • Docker容器中修改mysql最大连接数(永久)
    程序连接mysql报错:Toomanyconnections,解决方法是修改mysql里的连接数。showvariableslike"%conn%";    查看 max_connections最大连接数,max_user_connections单用户最大连接数。进入docker内部的bash命令可执行界面:dockerps   查看mysql镜像......
  • windows 环境下启动多个tomcat
    在Windows环境下面测试tomcat集群时,由于在环境变量中配置了catalina_home,导致每次启动都会走默认的配置,无法启动多个tomcat 修改方法直接修改startup.bat文件,设置CATALINA_HOME默认值。设置成tomcat安装路径即可setCATALINA_HOME=D:\programs\tomcat-cluster\apache-tomcat-8......