我正在使用CURL开发一个php站点,但它只适用于我的本地服务器而不是实时服务器.它返回错误'无法连接到主机'
CURL安装在实时服务器上,我测试了它.
SSL安装在实时服务器上,我使用curl连接到端口9301
即; 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;
Run Code Online (Sandbox Code Playgroud)
从我的测试中可以看出,我无法通过Curl连接到端口地址.要连接到端口地址,需要更改任何服务器设置吗?
curl_setopt($ch, CURLOPT_PORT, '9301');
Run Code Online (Sandbox Code Playgroud)
那是你的问题.手柄不在$ch
你的情况下,但是$session
.
我想是一个错字.
通常:确保在开发期间显示所有错误.记录它们或将它们放在屏幕上.你会很容易地抓住这个.
归档时间: |
|
查看次数: |
2459 次 |
最近记录: |