使用PHP调用一个API时出错。
错误:
Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /opt/lampp/htdocs/test/otp.php on line 8
Warning: include(http://api.msg91.com/api/sendotp.php?authkey="15529*************"&mobile="9937229853"&message="Your verification code is:1111"&sender="Subhrajyoti"&otp="1111"): failed to open stream: no suitable wrapper could be found in /opt/lampp/htdocs/test/otp.php on line 8
Warning: include(): Failed opening 'http://api.msg91.com/api/sendotp.php?authkey="15529*************"&mobile="9937229853"&message="Your verification code is:1111"&sender="Subhrajyoti"&otp="1111"' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/test/otp.php on line 8
我正在解释下面的代码。
$authkey="15529*************";
$mobile=9937229853;
$code=1111;
$message="Your verification code is:".$code;
$sender="Subhrajyoti";
$otp=1111;
include ('http://api.msg91.com/api/sendotp.php?authkey="'.$authkey.'"&mobile="'.$mobile.'"&message="'.$message.'"&sender="'.$sender.'"&otp="'.$otp.'"');
这里我试图发送OTP但收到这些消息。在这里,我需要发送OTP并获得响应。
答案 0 :(得分:1)
您可以使用CURL
或file_get_contents
。
$response = file_get_contents('http://api.msg91.com/api/sendotp.php?authkey="'.$authkey.'"&mobile="'.$mobile.'"&message="'.$message.'"&sender="'.$sender.'"&otp="'.$otp.'"');
$response = json_decode($response);
或 使用cURL:
$ch = curl_init();
$data=array('authkey'=>$authkey,'mobile'=>$mobile,'message'=>$message);//all parameter
curl_setopt($ch, CURLOPT_URL, 'http://api.msg91.com/api/sendotp.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
答案 1 :(得分:0)
而不是这一行:
$(this)
使用include ('http://api.msg91.com/api/sendotp.php?authkey="'.$authkey.'"&mobile="'.$mobile.'"&message="'.$message.'"&sender="'.$sender.'"&otp="'.$otp.'"');
点击附加了邮件和手机号码的网址,并从中获取响应。并且不要忘记使用cURL
函数对整个网址进行编码。
例如:
urlencode()