通过卷曲和PHP
问题描述:
我使用curl开发PHP站点连接到一个端口地址,但它仅适用我的本地服务器上,而不是在现场server.It返回错误“无法连接主机”通过卷曲和PHP
CURL安装在实时服务器上,我测试过了。
SSL已安装Live服务器上,我连接到端口9301使用curl
即; HTTP://xx.xxx.xx.xxx:9301 /测试。
这里是我的代码:
$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_setopt($ch, CURLOPT_PORT, '9301');
这就是你的问题。在你的情况下,句柄不是$ch
,而是$session
。
只是我猜错了。
一般情况下:确保在开发过程中显示ALL错误。记录它们或将它们放在屏幕上。 你会很容易地抓住这个。
您正在使用ssl,但您的地址以“http”开头? – Tomer 2012-07-25 10:01:56
可能是因为您的主机的防火墙阻止了该端口,您可能需要检查它们。编辑:也可能是您的主机拒绝没有用户代理存在的请求。 – Crisp 2012-07-25 10:41:33