Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP以循环的方式向远程服务器迭代发送post请求?_Php_Wordpress_Intuit Wasabi - Fatal编程技术网

如何使用PHP以循环的方式向远程服务器迭代发送post请求?

如何使用PHP以循环的方式向远程服务器迭代发送post请求?,php,wordpress,intuit-wasabi,Php,Wordpress,Intuit Wasabi,根据阵列的大小,我尝试多次向服务器发送数据。循环一次正确地发送数据,但此后不发送。我的代码是: $id = "uuid" //dynamic $username = "emailadd@example.com"; $password = "password"; $serverurl = "http://0.0.0.0:8080/api/v1/experiments/". $id .

根据阵列的大小,我尝试多次向服务器发送数据。循环一次正确地发送数据,但此后不发送。我的代码是:

    $id = "uuid" //dynamic  
    $username = "emailadd@example.com";
    $password = "password";
    $serverurl = "http://0.0.0.0:8080/api/v1/experiments/". $id ."/buckets";

    $alloc = floor((1 / sizeof($arrayAsBigAsValueArray)) * 100) / 100;
    $sum = 0;
    for ($x = 0; $x < sizeof($valuearray); $x++){

        $datasobj = array(
            "label" => $arrayAsBigAsValueArray[$x], 
            "allocationPercent" => $alloc,
            "payload" => json_encode(array('mykey'=>$valuearray[$x]),JSON_UNESCAPED_SLASHES)
        );

        if($x< sizeof($valuearray)-1){
            $sum += $alloc;
        }
        else{
            if((1 - $sum) != 0){
                $datasobj ["allocationPercent"] = (1 - $sum); 
            }
        }

        $headers = array(
            "Content-type: application/json",
            "Authorization: Basic " . base64_encode("$username:$password")
        );

        $ch = curl_init($serverurl);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLINFO_HEADER_OUT, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $datasobj);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $result2 = curl_exec($ch);
        curl_close($ch);
    }
$id=“uuid”//dynamic
$username=”emailadd@example.com";
$password=“password”;
$serverurl=”http://0.0.0.0:8080/api/v1/experiments/". $id.“/buckets”;
$alloc=地板((1/sizeof($arrayAsBigAsValueArray))*100)/100;
$sum=0;
对于($x=0;$x$arrayAsBigAsValueArray[$x],
“allocationPercent”=>$alloc,
“有效负载”=>json_编码(数组('mykey'=>$valuearray[$x]),json_未缩放的斜杠)
);
如果($x

这个函数是从WordPress的AdminAjax调用的,javascript函数调用它。当X>0时,我得到一个400错误。我怎样才能解决这个问题?我正在尝试使用Wasabi A/B api,它可以是。

400从哪里来?你的服务器还是芥末

如果是从芥末,在你的卷曲要求,我怀疑一个速率限制的API。您必须在请求之间设置延迟。最简单的是sleep()

或者

是否有多个授权密钥,每个请求一个?数组是否正确填充


检查400个错误:

此“睡眠”呼叫将转到哪里?它会在for循环的末尾运行吗?我可以推一个桶,但不能推多个。for循环每次迭代一个bucket。还有,我想你拿错芥末了。这是我的芥末:即使我将身份验证放在循环中,我仍然会得到相同的400错误!
"payload" => json_encode(array('mykey'=>$valuearray[$x])...