简体   繁体   English

网址仅在PHP中使用curl执行的get参数:获取错误

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

I am sending sms sending api through php curl. 我正在发送短信,通过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;
}

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. 我将从api服务中收到错误消息,但是,当我直接在浏览器中从此echo $url复制url时,它将正常工作。 But when using curl i will get the error message. 但是当使用curl我会收到错误消息。

Here is it 就这个

Sender ID Does not Exist or Pending or Route Invalid! 发件人ID不存在,未决或路由无效!

With curl it didn't worked. 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.

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