在本地主机上的短信工作
我使用curl命中了一个api,我在localhost上尝试了此方法,并且可以正常运行,但是当我将相同方法复制到实时网站时,它停止在实时网站上工作。
$ msg =“这里有一些自定义消息”;$msgencoded = urlencode($msg);
//包含消息$numEncode = urlencode($telePhone);
//电话被占用
注意:我正确获取了此变量。 $telephone
按照API文档的 API $url = "http://msg_server_website.com:8080/SMSAPI.jsp?
username=user_name&
password=user_pwd&
sendername=sender_name&
mobileno=".$numEncode."&message=".$msgencoded."";
My curl function which is working on localhost.
$data = $msg;
$crl = curl_init();
curl_setopt($crl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($crl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_HEADER, 0);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, 1);
curl_setopt($crl, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($crl);
if ($response) {
// if curl_exec() returned false and thus failed
echo 'everything was successful';
}
else {
echo 'An error has occurred: ' . curl_error($crl);
}
curl_close($crl);
更新1:error has occurred: Failed to connect to websitename.com port 8080: Connection refused
我尝试了很多次,但都收到了这个错误。在这种情况下该怎么办。
更新2
客户端服务器上8080端口被阻止。怎么办,如何解锁端口。
更新3
我的问题现在已经解决,因为在我的情况下,其8080的PORT问题在客户端主机上不是免费的,现在一切都会按预期进行。
谢谢大家的支持。
最佳答案
为了结束这篇文章,我将其发布为答案。
我的问题现在已经解决,因为在我的情况下,其8080的PORT问题在客户端主机上不是免费的,现在一切都会按预期进行。
我与服务器提供商(本例中为Godady)进行了检查。由于客户端使用共享主机,因此无法为个人释放端口。
因此我与短信提供商进行了交谈,他们建议对端口进行一些更改,并且我的API现在可以成功运行。
关于php - 我无法在实时服务器上使用curl方法运行api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45116774/