我正在使用印度的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。请求的格式错误。
我做错了。??
更新但是当我没有卷曲时运行正常
<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>
当我单击此链接时,它可以正常工作
假设直接链接有效,因为发送了请求所需的所有标头。
我相信缺少User-Agent:
标题或Connection:
标题
试试这个:
$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;
如果不起作用,请尝试添加Connection:
标题:
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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句