简体   繁体   中英

Url With only get parameters executing with curl in php:getting error

I am sending sms sending api through php curl.

<?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;
}

i will get the error message from the api service ,however when i copy the url from this echo $url directly on browser it will works fine. But when using curl i will get the error message.

Here is it

Sender ID Does not Exist or Pending or Route Invalid!

With curl it didn't worked.

将用户代理添加到您的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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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