我試圖根據(jù)數(shù)組的大小多次向服務(wù)器發(fā)送數(shù)據(jù)。該循環(huán)一次正確發(fā)送數(shù)據(jù),但此后不再發(fā)送數(shù)據(jù)。我的代碼是: $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); }這個(gè)函數(shù)是從 WordPress 的 admin-ajax 調(diào)用的,并且有一個(gè) javascript 函數(shù)調(diào)用它。當(dāng) X > 0 時(shí),我收到 400 錯(cuò)誤。如何解決此問(wèn)題?我正在嘗試使用 Wasabi A/B api,可以在此處找到。
如何使用 PHP 在循環(huán)中迭代地將 post 請(qǐng)求發(fā)送到遠(yuǎn)程服務(wù)器?
墨色風(fēng)雨
2023-09-08 21:39:21