我使用curl打了一个API,我试图在本地主机上这种方法及其工作罚款,我想,但是当我将同样的方法复制到现场网站,停止在现场网站上工作。
$ msg =“一些自定义信息在这里”;
$msgencoded = urlencode($msg); //消息enocded
$numEncode = urlencode($telePhone); //电话是enocded
注:我正确得到这个变量。 $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
我想很多次,我得到这个错误。在这种情况下做什么。
UPDATE 2
8080端口被阻塞客户端的服务器上。该怎么办,如何解锁该端口。
更新3 我的问题是现在解决了,因为在我的情况下8080的港口问题,它不是免费的客户端的主机,现在过的事情按预期工作的。
谢谢大家的支持。
+0
这段代码不应该在你的本地主机上运行,因为你实际上在你的if语句(它也会删除curl处理程序'$ crl')之前_closing_ curl。你已经得到了回应,在你的if语句中使用它,而不是试图再次进行相同的调用。 –
+0
@我只在现场网站上添加了这个错误检查部分,更新代码后我得到了以上错误。你能看到一次吗? –
+0
你还在拨打电话两次。尝试检查'if($ response)'而不是,因为你已经有了结果。该网站可能会防止来自同一客户端的两个相同的呼叫直接接连。此外,你应该真的'urlencode()'电话号码和消息。 –