0
我有簡單的腳本,通過REST與某些服務器通信。 服務器架構有一些漏洞,我現在正在與其中一個打架。 當我發送一個請求來分配一些配置文件,而不是等待響應併發送第二個請求。 它基本上只是取消第一個請求,只做第二個請求。PHP - 等待回覆
我的代碼如下所示:
$this->assignProfile($token, $id, FIRST);
$this->assignProfile($token, $id, SECOND);
我的指定配置文件的方法是這樣的:
public function assignProfile($token, $organizationId, $profileId)
{
//define enviroment and path
$host = enviroment;
$path = "/admin/members/".$organizationId."/assigned-profiles";
$data_string = '["'.$profileId.'"]';
// set up the curl resource
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host.$path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$token.'',
'Content-Length: ' . strlen($data_string)
));
echo "<br>OK<br>";
// execute the request
$output = curl_exec($ch);
curl_close($ch);
}
的事情是,web服務不響應與任何機構或東西,它只是用代碼200響應。 我該如何編碼這個等待200並且繼續第二個請求。
Ty,不知道這個CURL函數。 :) – Andurit