如何用PHP curl发送GET请求
问题描述:
我想用PHP curl或file_get_contents函数发送GET请求时遇到问题!!! 我认为这个问题是为我的网址! 请帮我...我 码(的file_get_contents功能):如何用PHP curl发送GET请求
$SMStext = "text";
$SMSmobile = 'phonenumber';
$SMSurl = "http://api.payamak-panel.com/post/sendsms.ashx?username=username&password=pass&from=smsnumber&to=";
$SMSurl .= $SMSmobile;
$SMSurl .= '&text=';
$SMSurl .= $SMStext;
echo file_get_contents($SMSurl);
我的代码(PHP的卷曲):
$SMStext = "text";
$SMSmobile = 'phonenumber';
$SMSurl = "http://api.payamak-panel.com/post/sendsms.ashx?username=username&password=pass&from=smsnumber&to=";
$SMSurl .= $SMSmobile;
$SMSurl .= '&text=';
$SMSurl .= $SMStext;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$SMSurl);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
// curl_setopt($ch,CURLOPT_HEADER, false);
$output=curl_exec($ch);
curl_close($ch);
echo $output
答
这个URL重定向到另一个网址。
您需要添加:curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
的可能的复制[PHP卷曲GET请求,请求体(https://*.com/questions/17230246/php-curl-get-request-and-requests-body) –