【发布时间】:2012-07-25 09:59:35
【问题描述】:
我正在使用 CURL 开发一个 php 站点,但它只能在我的本地服务器上运行,而不能在实时服务器上运行。它返回错误“无法连接到主机”
CURL iS 安装在实时服务器上,我已经对其进行了测试。
SSL 安装在实时服务器上,我正在使用 curl 连接到端口 9301
即;http://xx.xxx.xx.xxx:9301/test.
这是我的代码:
$request = 'http://xx.xxx.xx.xxx:9301/test';
// The request parameters
$context = 'something';
// urlencode and concatenate the POST arguments
$postargs = 'xmlRequest='.urlencode($context);
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt($ch, CURLOPT_PORT, '9301');
curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
//echo curl_getinfo($session);
echo $err = 'Curl error: ' . curl_error($session);
curl_close($session);
echo $response;
根据我的测试,很明显我无法通过 Curl 连接到端口地址。为了连接到端口地址,需要更改任何服务器设置吗?
【问题讨论】:
-
您使用的是ssl,但您的地址以“http”开头?
-
可能是您主机的防火墙阻止了该端口,您可能需要与他们核实一下。编辑:也可能是您的主机拒绝了没有用户代理的请求。