我真的对cURL感到困惑。
示例:
我可以使用旧的cURL代码访问
cikpoo.com/会员/卡号/ $ card_number
但是如果我想那样访问
cikpoo.com/会员/卡号/ $ card_number / dateSEP / $ date
如何编写代码?
这是我的代码
foreach($member_data as $row){
$cardnumber=$row->cardnumber;
$date=$row->date;
}
if($cardnumber==''){
echo "enter your card number";
}else{
$url = $data_b->service_url; //url is cikpoo.com/
$ch = curl_init($url.'Member/cardnumber/'. $cardnumber .'/dateSEP/'. $date ); //problem here
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);//json file
curl_close($ch);
答案 0 :(得分:-1)
此示例中包含一些错误报告。这并不意味着答案。只是一个带有错误检查的有效示例。
$url = 'https://www.w3schools.com/';
$curl = curl_init($url .'js/ajax_info.txt');
curl_setopt($curl, CURLOPT_HTTPGET, true);
//curl_setopt($curl, CURLOPT_HTTPHEADER, $http_header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
if(!$result){
echo('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
curl_close($curl);
echo '<br>'.$result;