1
我試圖發送api請求與guzzle和cURL從sub1.example.local(本地主機)到sub2.example.local(localhost)。這兩個laravel 5.4項目。但它使用sub1.example.local的數據庫。從sub1.example.local(本地主機)到sub2.example.local(本地主機)的cURL/Guzzle請求使用相同的數據庫
即使使用session_write_close();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://sub2.example.local/api/user/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "email=\"[email protected]\"&password=\"big_secret\"");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_CONNECT_TO, ['hesabatlar.local','80','sub2.example.local','80']);
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'Host: hr.hesabatlar.local';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
session_write_close();
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);