我在这里搜索了许多以前的帖子,但似乎没有任何内容可以解决我的问题。简而言之,我希望在下面的代码中包含一个 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;