PHP:网站托管时无法发送http请求

时间:2013-02-01 23:10:54

标签: php httpwebrequest

我正在编写一个Web应用程序,我已将sms集成到我的代码中。我的应用程序在我的localhost上运行完美,我可以通过curl或php中的file_get_contents发送http请求,获取响应并处理它。

但是我刚刚托管了该网站,我现在在发送http请求时遇到问题,因为它是在线托管的。我用curl和file_get_contents尝试了它,没有用。

然后我决定在不同提供商的另一台服务器上托管该网站,但仍然无法发送请求。我也没有收到任何错误消息。我一直在我的localhost上测试它,以确保它不是来自脚本,我100%确定它不是来自我的代码。

我联系了客户支持,但他们没有任何帮助。

我真的被困住了,我需要帮助。谢谢。请求我在下面的代码中找到摘录:

假设已经定义了变量......

<?php
.................................

// the url contains my password and username so i took it off
$url = "";
$response = file_get_contents($url);

/*
// this is the curl part and it works if I decide to use it instead
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
curl_close($ch);
*/
$result = explode("|", $response);

1 个答案:

答案 0 :(得分:1)

file_get_contents()经常被IT部门和托管服务提供商禁用,因为如果不谨慎使用它会导致地狱。那将是我要检查的第一件事。