使用axios POST将数据发送到FLASK API

时间:2020-07-22 14:40:36

标签: json reactjs flask post axios

我正在尝试将带有axios帖子的数据发送到Flask api。数据描述如下:-

this.state.graph.getModel().cells是字典的列表,例如:-

0: mxCell {value: undefined, geometry: undefined, style: undefined, children: Array(1), id: "0", …}
1: mxCell {value: undefined, geometry: undefined, style: undefined, parent: mxCell, id: "1", …}
2: mxCell {value: taskobject, geometry: mxGeometry, style: "verticalLabelPosition=top;", id: "2", vertex: true, …}
3: mxCell {value: port, geometry: mxGeometry, style: "port;portConstraint=east;perimeter=none;shape=triangle;routingCenterX=0.3;routingCenterY=0;", id: "3", vertex: true, …}

this.state.graphNetwork是一个包含字符串的简单列表。

this.state.currentNode是与上述列表中的词典之一格式相似的词典。

var formData = new FormData();
    console.log(this.state.graph.getModel().cells);
    formData.append("model", this.state.graph.getModel().cells);
    formData.append("network", this.state.graphNetwork);
    formData.append("currentNode", this.state.currentNode);

    http.post("run_node", formData, {
      headers: {
        "content-type": "multipart/form-data",
      },
    })

当我在烧瓶中接收到数据时,this.state.graphNetwork作为字符串而不是字符串列表被接收。字典和词典的列表以[object Object]的形式接收。

如何以原始格式发送字典?我尝试过JSON.Stringify,但它给出了cannot convert circular object例外。

0 个答案:

没有答案