PHP将json发布到服务器导致重复插入数据

时间:2016-09-17 09:58:43

标签: php json api

我尝试使用以下代码将JSON发布到服务器API端点,这会导致插入重复条目。

$fileBinStr = $_POST['fileBinStr'];这需要发布大量的图像base64字符串。但是,如果我删除此行,它将只插入1个条目。

问题:无论如何,我是否要阻止重复输入插件或我错误地执行了哪一部分?

 $billNumber = $_POST['billNumber'];
 $billType = $_POST['billType'];
 $geoLocationX = $_POST['geoLocationX'];
 $geoLocationY = $_POST['geoLocationY'];
 $authToken = $_POST['authToken'];
 $fileName = $_POST['fileName'];
 $fileBinStr = $_POST['fileBinStr'];
 $data = array(
    'command' => 'Uploadphoto',
    'billNumber' => $billNumber,
    'billType' => $billType,
    'geoLocationX' => $geoLocationX,
    'geoLocationY' => $geoLocationY,
    'fileName' => $fileName,
    'fileBinStr' => $fileBinStr,
    'authToken' => $authToken
    );
    $data_json = json_encode($data);
    $data = base64_encode($data_json);
    $url ="{myendpoint}";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data)));
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response1  = curl_exec($ch);

        $obj=json_decode($response1,true);
        foreach($obj as $key => $value){
         // decode the $value string
        $value = json_decode($value, true);
        $result = $obj['result'];

0 个答案:

没有答案