php curl hostname,php – 如何解决cURL错误(7):无法连接到主机?
我使用cUrl(php)以xml格式將項(xiàng)目代碼發(fā)送到Web服務(wù)。我在localhost中得到正確的響應(yīng),但是當(dāng)它做服務(wù)器它顯示
cURL Error (7): couldn’t connect to host
這里是我的代碼:
function xml_post($post_xml, $url)
{
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
// curl_setopt($ch, CURLOPT_PORT, $port);
$data = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if ($curl_errno > 0) {
echo "cURL Error ($curl_errno): $curl_error\n";
} else {
echo "Data received\n";
}
curl_close($ch);
echo $data;
}
我將項(xiàng)目代碼發(fā)送到計(jì)數(shù)器并從中獲取詳細(xì)信息。我試圖使用版本php 4和php5,沒(méi)有工作任何解決方案。
總結(jié)
以上是生活随笔為你收集整理的php curl hostname,php – 如何解决cURL错误(7):无法连接到主机?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。