让我们从简单的图表开始:
Local www server for testing purposes (application A)
(127.0.0.1:80)
\->-cUrl call->-\
\
WebService Server (application B)
(1.1.1.1:7777)
/
/->-cUrl call->-/
Hosting www server (application A)
(2.2.2.2:80)
我有两个应用程序:
应用程序A使用cUrl从Application B获取数据。负责此调用的函数如下所示(函数在应用程序A中使用,$ url是应用程序B的地址):
private function loadData($ids) {
$url = 'http://1.1.1.1:7777/loadData';
$data = 'data=' . json_encode($ids);
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($c);
$decoded = json_decode($result);
if (!$decoded) {
Logger::logInfo(sprintf('Unable to decode json [result=%s]', $result));
}
if (curl_errno($c)) {
Logger::logInfo(sprintf('cUrl error: [errno: %s; errmsg: %s]', curl_errno($c), curl_error($c)));
}
return $decoded;
}
问题是......
通过端口7777进行的卷曲调用可以从本地服务器正常工作,但不能从托管服务器工作。如果我使用标准端口80代替端口7777,它可以正常工作。问题出在哪儿?是托管服务器上的防火墙吗?
结论:
**Works**: Local www server (application A) ->-cUrl call->- WebService Server (application B) (1.1.1.1:7777)
**Works**: Local www server (application A) ->-cUrl call->- WebService Server (application B) (1.1.1.1:80)
**Works**: Hosting www server (application A) ->-cUrl call->- WebService Server (application B) (1.1.1.1:80)
**Does not work**: Hosting www server (application A) ->-cUrl call->- WebService Server (application B) (1.1.1.1:7777)