简体   繁体   English

如何使用php curl发送GET请求

[英]How to send GET request with php curl

I have a problem when I want to send a GET request with php curl or file_get_contents function !!! 当我想使用php curl或file_get_contents函数发送GET请求时遇到问题! I think this problem is for my URL !!! 我认为这个问题是我的网址! please help me ... my code (file_get_contents function): 请帮助我...我的代码(file_get_contents函数):

$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);

my code (php curl): 我的代码(php curl):

$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

This URL redirects to another URL. 该URL重定向到另一个URL。
You need to add: curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 您需要添加: curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM