打开 URL 在本地主机上成功,但在生产环境中失败



我已经成功地使用"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 GuzzleHttpClient();
$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'
                ]
]);

我想再次提到,相同的代码正在从本地主机成功运行!

尝试该解决方案来重命名.env文件。

从。env.example根文件夹中的.env

最新更新