我试图根据数组的大小多次向服务器发送数据。该循环一次正确发送数据,但此后不再发送数据。我的代码是:
$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);
}
这个函数是从 WordPress 的 admin-ajax 调用的,并且有一个 javascript 函数调用它。当 X > 0 时,我收到 400 错误。如何解决此问题?我正在尝试使用 Wasabi A/B api,可以在此处找到。
森林海