2013-02-01 51 views
0

我正在编写一个web应用程序,并且已将短信集成到我的代码中。我的应用程序在本地主机上运行完美,我可以通过curl或file_get_contents在PHP中发送http请求,获取响应并处理它。PHP:当网站在线托管时无法发送http请求

但是,我刚刚主持了该网站,并且我现在在发送http请求时遇到问题,因为它已在线托管。我用curl和file_get_contents试了一下,都没有工作。

然后我决定从另一个提供商的另一台服务器上托管该站点,但我仍然无法发送请求。我也没有收到任何错误消息。我一直在我的本地主机上测试它,以确保它不是来自脚本,我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); 
+0

你有什么错误吗? – datasage

+0

用'<?php phpinfo()创建一个新文件; ?>',运行它并查看'allow_url_fopen'是否设置为'On'。或者从命令行'php -r'phpinfo();“ | grep'allow_url_fopen'' – castis

+0

好的,我正在检查php信息。会尽快让你知道。 – mandeeya

回答

1

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