【发布时间】:2018-02-04 18:37:48
【问题描述】:
我已经成功使用“get_file_contents()”php函数、curl函数和guzzlehttp包打开了一个url。
但是当我在生产服务器上使用相同的代码时,所有提到的方法都会失败。
“get_file_contents”导致此错误:
file_get_contents(https://example.com:xxxx/bulksms/bulksms?username=xxx&password=xxx&type=0&dlr=1&destination=xxx&source=xxx&message=xxx):打开流失败:连接被拒绝
虽然“guzzlehttp”导致此错误:
cURL 错误 7:无法连接到 example.com 端口 xxxx:连接被拒绝(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html)
“get_file_contents”的使用代码:
$url = 'http://example.com:xxxx/bulksms/bulksms?username=xxx&password=xxx&type=0&dlr=1&destination=xxx&source=xxx&message=xxx';
return file_get_contents($url);
“guzzlehttp”使用代码:
$client = new \GuzzleHttp\Client();
$api_link = 'https://xx.example.com:xxxx/bulksms/bulksms';
$result = $client->get($api_link, [
'query' => [
'username' => 'xxx',
'password' => 'xxx',
'type' => 0,
'dlr' => 1,
'destination' => 'xxx',
'source' => 'xxx',
'message' => 'xxx'
]
]);
我想再次提一下,相同的代码在 localhost 中成功运行!
【问题讨论】:
-
您的服务器可能存在防火墙或限制问题。