[英]Url With only get parameters executing with curl in php:getting error
我正在发送短信,通过php curl发送api。
<?php
$number='XXXXXX';
$message="Hello world";
$url='http://XXx/api/sendmsg.php?user=XXXXX&pass=XXX&sender=SPOTMT&phone='.$number.'&text='.$message.'&priority=ndnd&stype=normal';
echo $url;
echo httpGet($url);
function httpGet($url)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
我将从api服务中收到错误消息,但是,当我直接在浏览器中从此echo $url
复制url时,它将正常工作。 但是当使用curl
我会收到错误消息。
就这个
发件人ID不存在,未决或路由无效!
curl
没有奏效。
将用户代理添加到您的curl请求中,因为后端可能会过滤具有默认curl用户代理的请求。
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
使用urlencode()对消息进行编码,然后再将其提交给CURL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.