我已经成功地使用"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'
]
]);我想再次提到,相同的代码正在本地主机上成功地工作!
发布于 2018-02-04 19:06:17
尝试该解决方案重命名您的.env文件。
从.env.example到根目录中的.env。
https://stackoverflow.com/questions/48611683
复制相似问题