我使用cUrl(php)將項目代碼以xml格式發送到Web服務。我得到了本地主機的正確反應,但是當這樣做服務器它顯示如何解決cURL錯誤(7):無法連接到主機?
捲曲錯誤(7):無法連接到主機
這裏是我的代碼:
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;
}
我將物品代碼發送到Tally並從中獲取詳細信息。我嘗試使用版本php 4+和php5 +,沒有任何解決方案。
選擇使用端口80 – 2013-11-13 14:46:26
使用捲曲詳細選項,以獲得更多的信息 – Preexo 2014-01-31 17:39:57
我將在這裏補充兩點,最終得到了我的問題解決了代理: 1.運行卷曲在命令行中使用'--verbose ' 2.如果你在使用Little Snitch(或類似的)的OSX上,看看那個。 – 2016-07-19 21:48:43