【问题标题】:opening url succeeds on localhost but fails on production打开 url 在 localhost 上成功,但在生产中失败
【发布时间】: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 中成功运行!

【问题讨论】:

  • 您的服务器可能存在防火墙或限制问题。

标签: php laravel curl sms


【解决方案1】:

尝试使用该解决方案重命名您的 .env 文件。

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

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 2019-06-30
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 2012-04-19
    相关资源
    最近更新 更多