duanlang0025 2018-12-31 18:00
浏览 50

dreamfactory rest api服务器php脚本POST请求pre_process循环运行插入到mysql数据库的很多行

in dreamfactory rest api backend server I have written this php script that is triggered with a POST request in a pre process workflow. This script replaces the received payload with a default payload like this:

{"resource": [{"Time":"2018-12-21T07:49:23","Gas":"111111","Pressure":"1111","Temperature":"11111"}]}

that it will be insert into mysql database table "T":

<?php

$options = [];
$options['headers'] = [];
$options['headers']['Content-Type'] = 'application/json';
$options['parameters'] = [];
$options['parameters']['api_key'] = 'MY_API_KEY';

$api = $platform['api'];
$post = $api->post;

// json string
$json = '{"resource":   [{"Time":"2018-12-21T07:49:23","Gas":"111111","Pressure":"1111","Temperature":"11111"}]}';
// converts json to php array
 $newpayload = json_decode($json, true);

// makes POST call
$result = $post("sensor_sql/_table/t", $newpayload, $options);

var_dump($result);
?>

But when I send a post request to my api rest dreamfactory server with "Fiddler4" program my rest api insert into mysql database many row with the payload like this one: {"Time":"2018-12-21T07:49:23","Gas":"111111","Pressure":"1111","Temperature":"11111"}]} and not only one as it should be. It seems that the script runs many times and not only one when it is called during pre process. Is something missing in my script ? Why the script inserts many row in mysql database and not only one ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题