我尝试了here中的以下代码,但出现了一个名为“找不到HttpRequest类”的错误。我使用的是php版本5.6.8(xampp v3.2.1)。任何人请帮帮我。
<?php
$request = new HttpRequest();
$request->setUrl('https://api.infobip.com/sms/1/text/single');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders(array(
'accept' => 'application/json',
'content-type' => 'application/json',
'authorization' => 'Basic sfdsdf==' // name&password
));
$request->setBody('{
"from":"test", //from
"to":"000", // number
"text":your verification code is = 000."
}');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}发布于 2015-12-02 14:51:12
$mob_no="mobile number";
$msg="Your message";
$sender_id='your sender id eg:VJPOTPYTL';
$str = trim(str_replace(' ', '%20', $msg));
$url="http://dnd.9starabs.com/app/smsapi/index.php?key=55942cc305ef6&type=text&contacts=".$mob_no."&senderid=".$sender_id."&msg=".$str."";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_exec($ch);
curl_close($ch);发布于 2015-12-02 15:01:16
由于你使用的是php 5.4或更高版本,似乎没有php_http.dll文件可以包含在你的扩展库中(除非有人能找到我遗漏的文件??)。
我能找到的唯一一个错误是在更新php.ini配置文件以包含扩展后启动Apache服务器时产生的错误。
检查this link。省省吧。
然后尝试这个程序:
include_once('HttpRequest.php'); //where HttpRequest.php is the saved file
$url= 'http://www.google.com/';
$r = new HttpRequest($url, "POST");
var_dump($r->send()); 如果它不工作,那么您可能需要自己编译HTTP包。You can find more here.
发布于 2015-12-03 00:04:03
解决方案是安装PECL php扩展。在堆栈溢出问题上给出了几次答案,比如在这个线程上:
"PHP Fatal error: Class 'HttpRequest' not found"
你可以使用CURL代替PECL通过web应用程序发送短信。在Infobip的博客上有很好的解释和描述。我建议你试一试:
http://www.infobip.com/blog/step-by-step-php-tutorial/
https://stackoverflow.com/questions/34036380
复制相似问题