我在這裡搜尋了許多以前的帖子,但似乎沒有任何內容可以解決我的問題。簡而言之,我希望在下面的程式碼中包含一個 PHP 變數。下面的程式碼可以正常工作,因為它是硬編碼的,但是當我用變數 $hid
(已聲明)替換單字 MAYIAHH 時,出現錯誤。
我已經嘗試過 CURLOPT_POSTFIELDS
和各種方法,但似乎沒有任何幫助。請問有什麼想法嗎?
function send_request($xml) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://rest.reserve-online.net/availability?properties=MAYIAHH'); curl_setopt($ch, CURLOPT_USERPWD, "uname:pass"); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close($ch); return $result; }
P粉7712333362024-02-26 11:19:25
您是否嘗試過連接 url 字串?
$hid = 'MAYIAHH'; $url = 'https://rest.reserve-online.net/availability?properties='.$hid; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, "uname:pass"); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close($ch); return $result;