Php 请求URI太长-SMS API
我的问题有点奇怪。我从我的提供商处获得了此bulksms api:Php 请求URI太长-SMS API,php,apache,api,curl,bulksms,Php,Apache,Api,Curl,Bulksms,我的问题有点奇怪。我从我的提供商处获得了此bulksms api: http://www.estoresms.com/smsapi.php?username=user&password=1234&sender=@@sender@@&recipient=@@recipient@@&m essage=@@message@@& 然后我用PHP包装它,并用cURL传递它: $api = "http://www.estoresms.com/smsapi.php?u
http://www.estoresms.com/smsapi.php?username=user&password=1234&sender=@@sender@@&recipient=@@recipient@@&m
essage=@@message@@&
然后我用PHP包装它,并用cURL传递它:
$api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers."&message=".$text."&";
function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$send_it = curl_get_contents($api);
通常,它工作正常,但当$recepient(电话号码)超过300时,我会得到一个错误:
请求URI太长
请求的URL长度超出了此服务器的容量限制。
此外,尝试使用ErrorDocument处理请求时遇到414请求URI过长错误。
但是BulkSMS应该能够一次发送数千个号码。
从我的研究中,我发现URL是有限制的。我不是服务器的所有者。我正在制定一个共享托管计划。请告诉我如何解决这个问题。我知道有一个解决方案,并不意味着要买我自己的服务器
谢谢你能试着让API使用POST而不是GET吗。这将解决这个问题 编辑: 我不确定您的API检查帖子,但请尝试:
$api = "http://www.estoresms.com/smsapi.php";
$data = array('username' => $sms_user, 'password' => $sms_pwd, 'sender' => $sender_id , 'recipient' => $numbers , 'message' => $text);
function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$send_it = curl_get_contents($api);
看看这个代码示例(来自bulksms.com)
因此,我必须找到解决自己问题的方法。如果API不允许一次使用数千个数字,那么让我们在执行时将其分成块
function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$how_many = count(explode(',', $numbers));
if ($how_many > 250){
$swi = range(0, ceil($how_many/250)-1);
foreach ($swi as $sw){$numbers_a = implode(',', (array_slice(explode(',', $numbers), $sw*250, 250)));
$api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers_a."&message=".$text."&";
$send_it = curl_get_contents($api);
}
}
if ($how_many <= 250){
$api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers."&message=".$text."&";
$send_it = curl_get_contents($api);
}
函数curl\u get\u contents($url)
{
$ch=curl\u init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
$data=curl\u exec($ch);
卷曲关闭($ch);
返回$data;
}
$how_many=计数(分解(',',$numbers));
如果($多少个>250个){
$swi=范围(0,ceil($多少/250)-1);
foreach($swi as$sw){$numbers_a=内爆(',',(数组_切片(explode(',',$numbers),$sw*250250));
$api=”http://www.estoresms.com/smsapi.php?username=“$sms_user.”和password=“.sms_pwd.”和sender=“.sender_id.”和recipient=“.numbers_a.”和message=“.text.”和“;
$send\u it=curl\u get\u内容($api);
}
}
如果($how_many Pls我怎样才能开始使用POST?谢谢,我已经尝试过了,它不起作用。即使是任何数字,无论是很少还是很多。我的原始代码都可以工作。问题是当数字太多时,它就失败了。这意味着API不读取POST数据,这很奇怪,因为据我所知,是它们被服务于请求的家伙?我认为这是其中之一有两种可能性,第一种:这是API限制电话号码数量的方式(一种奇怪的方式)。第二种:你通过一个代理进行阻止。如果是第一种,请尝试联系API并向他们披露你的问题。