zoukankan      html  css  js  c++  java
  • 原创:python的requests.post()向后端传递数据,数组结构需将python数据结果转换成JSON

     针对采集来的数据,用requests.post()向后端传递

    如果是python数据结构如数组,需要转换成为JSON对象,否则后端容易解析不成后端集合的对象结构 re

    一:python做为前端请求requests.post()

         '''
            后台接收是数组
            '''
            dataInfoList = [
                {
                    'area': 'string222',
                    'city': 'string',
                    'subject': 'request传递过去数据222'
                },
                {
                    'area': 'string222',
                    'city': 'string',
                    'subject': 'request传递过去数据333'
                }
            ]
            # 请求头,不设置会理解成表单form post无法传递数据
            headers = {"content-type": "application/json"}
            #json.dumps()作用 将一个Python数据结构转换为JSON
            return22 = requests.post("http://192.168.0.100/api/v1/infor/listTdInfo", json.dumps(dataInfoList),
                                     headers=headers)
            print("传递是对象****requests.post提交返回结果:", return22)
    

     二:spring boot 做为后端接收前端传递过来数据

      /**
        * 接收scrapy 传递过来的字典里加集合
        * */
        @PostMapping("/listTdInfo")
        @ApiOperation(value = "为测试scrapy向后端提交数据222")
        public void addPostListTdInfo(@RequestBody List<TdInfor> tdInfor){
            System.out.println("添加数据是对象的集合如下");
            System.out.println(tdInfor);
        }
    

      

    做产品的程序,才是好的程序员!
  • 相关阅读:
    Window 服务安装
    SQL
    vb To c# or c# To vb
    CacheHelper-缓存
    让Linq的OrderBy支持动态字段
    哪些列上适合建立索引???
    如何查看Oracle数据库中无效的对象,约束,触发器和索引
    如何查看Oracle中被锁定的表
    ORACLE ASM
    WebLogic Server
  • 原文地址:https://www.cnblogs.com/asplover/p/15680021.html
Copyright © 2011-2022 走看看