Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从php发送SMS时请求错误_Php_Curl_Sms Gateway - Fatal编程技术网

从php发送SMS时请求错误

从php发送SMS时请求错误,php,curl,sms-gateway,Php,Curl,Sms Gateway,我正在使用indiasms的api和curl发送短信 <?php $url = "http://12.23.54.18/api/smsapi.aspx?username=myusername&password=mypassword&to=7897015426&from=DEMOAB&message=Your message content."; $curl = curl_init($url); curl_se

我正在使用indiasms的api和curl发送短信

 <?php        

 $url = "http://12.23.54.18/api/smsapi.aspx?username=myusername&password=mypassword&to=7897015426&from=DEMOAB&message=Your message content.";            
 $curl = curl_init($url);
 curl_setopt_array($curl, array(
                    CURLOPT_RETURNTRANSFER => 1,
                    CURLOPT_URL => $url,
                    CURLOPT_USERAGENT => 'Codular Sample cURL Request'
                ));

 $resp = curl_exec($curl);
 curl_close($curl);

 ?>

每当我运行这个脚本时,我都会

错误请求

HTTP错误400。请求的格式不正确。

我做错了什么

更新,但当我不使用curl运行时,效果很好

<a href="http://12.23.54.18/api/smsapi.aspx?username=myusername&password=mypassword&to=7897015426&from=DEMOAB&message=Your message content.">Send Message</a>


当我单击此链接时,它正常工作

应该是直接链接工作,因为请求所需的所有头都已发送

我认为缺少
用户代理:
标题或
连接:
标题

试试这个:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://12.23.54.18/api/smsapi.aspx?username=myusername&password=mypassword&to=7897015426&from=DEMOAB&message=Your message content.');
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

echo $httpcode;
如果不起作用,请尝试添加,
连接:
标题:

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Connection: close'
));
如果不起作用,请在发送之前尝试重新输入您的“消息”:

$msg = rawurlencode('Your message content.');
curl_setopt($ch, CURLOPT_URL, 'http://12.23.54.18/api/smsapi.aspx?username=myusername&password=mypassword&to=7897015426&from=DEMOAB&message=' . $msg);

您是否对邮件进行URL编码?API文档怎么说?Cody,您的Web服务需要POST方法?@GuilhermeNascimento no@ʰᵈˑ这里没有关于URL编码的内容,我也猜,问题在于消息的编码。尝试对您的邮件进行rawurlencode。@Cody此Web服务需要验证cookie/会话,还是只使用“GET方法”?请参阅我编辑了答案。是否使用了
rawurlencode
?谢谢提示@Jonhi:)谢谢!美好的祝你的项目好运!让我们。