带有PHP的Curl Post代码段在localhost上工作,但在我的托管网页上不工作

带有PHP的Curl Post代码段在localhost上工作,但在我的托管网页上不工作,php,curl,xmlhttprequest,Php,Curl,Xmlhttprequest,我在本地和在线使用相同的代码片段。 在我的本地主机服务器上,我得到了200的HTTP状态码,我没有问题。 当我在当前托管的网页上使用相同的代码时,我得到的HTTP代码为0 下面是我用于HTTP调用的代码片段 $curl = curl_init(); // Set the options curl_setopt($curl,CURLOPT_URL, "http://xx.xxxxxxxxxx.xxx:xxxx/xx"); // This sets the number of fields to

我在本地和在线使用相同的代码片段。 在我的本地主机服务器上,我得到了200的HTTP状态码,我没有问题。 当我在当前托管的网页上使用相同的代码时,我得到的HTTP代码为0

下面是我用于HTTP调用的代码片段

$curl = curl_init();

// Set the options
curl_setopt($curl,CURLOPT_URL, "http://xx.xxxxxxxxxx.xxx:xxxx/xx");

// This sets the number of fields to post
curl_setopt($curl,CURLOPT_POST, 1);

// This is the fields to post.
curl_setopt($curl,CURLOPT_POSTFIELDS, "Data");

//execute the post
$session = curl_exec($curl);
//Echo Http Response Code
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

//close the connection
curl_close($curl);

有什么想法吗?

您的服务器上安装了curl吗?我也在使用curl进行其他用途,我的服务器没有问题。所以我猜它已经安装好了如果您连接到服务器,则可以从服务器获取返回代码,否则它将失败,您将获得0。因此,如果你尝试连接到“www.google.com/lksdfk”,你会得到一个400的返回码,如果你直接去google.com,你会得到302(如果你转发到下一个页面,你会得到200…我是这样做的,因为它转发到google.com.br,所以你可能得不到),如果你去“googlecom”,你会得到一个0(主机未找到),所以最后一个,没有人可以发回代码。