Guzzle post 无法使用外部 ip。抛出无法连接到 37.XX.XX.XXX 端口 80:连接超时
Guzzle post is not working with external ip. Throws Failed to connect to 37.XX.XX.XXX port 80: Connection timed out
我知道这个问题有很多答案,但没有用。
受影响的 Guzzle 版本:6.3
PHP版本:7.2.24
cURL版本:7.58.0
在 laravel 项目中使用 guzzle。
在本地 IP 上时一切正常。端口 80 对连接开放。
但是当使用外部(静态)l IP 时,它会显示以下错误
无法连接到 37.XX.XX.XXX 端口 80:连接超时
虽然当相同的 URL 直接用于浏览器或邮递员时,它可以使用外部 IP。我做了 google 并尝试了但没有任何效果。
我也试过普通卷曲。下面是代码。
$postData = [
'grant_type' => 'password',
'client_id' => 10,
'client_secret' => 'xHuxxxxxxxflw',
'username' => 'admin@abc.com',
'password' => 'abc',
'scope' => '*',
];
$ch = curl_init();
$url = 'http://37.XX.XX.XXX/oauth/token';
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$data = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if ($curl_errno > 0) {
echo "cURL Error ($curl_errno): $curl_error\n";
} else {
echo "Data received\n";
}
curl_close($ch);
echo ($data);
显示以下错误
cURL Error (7): Failed to connect to 37.XX.XX.XXX port 80: Connection timed out
谁能帮帮我?我花了很多时间来解决,但没有任何效果。
问题已通过允许出站端口解决。不允许出站端口,因此无法连接请求。
我知道这个问题有很多答案,但没有用。
受影响的 Guzzle 版本:6.3
PHP版本:7.2.24
cURL版本:7.58.0
在 laravel 项目中使用 guzzle。 在本地 IP 上时一切正常。端口 80 对连接开放。 但是当使用外部(静态)l IP 时,它会显示以下错误 无法连接到 37.XX.XX.XXX 端口 80:连接超时
虽然当相同的 URL 直接用于浏览器或邮递员时,它可以使用外部 IP。我做了 google 并尝试了但没有任何效果。
我也试过普通卷曲。下面是代码。
$postData = [
'grant_type' => 'password',
'client_id' => 10,
'client_secret' => 'xHuxxxxxxxflw',
'username' => 'admin@abc.com',
'password' => 'abc',
'scope' => '*',
];
$ch = curl_init();
$url = 'http://37.XX.XX.XXX/oauth/token';
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$data = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if ($curl_errno > 0) {
echo "cURL Error ($curl_errno): $curl_error\n";
} else {
echo "Data received\n";
}
curl_close($ch);
echo ($data);
显示以下错误
cURL Error (7): Failed to connect to 37.XX.XX.XXX port 80: Connection timed out
谁能帮帮我?我花了很多时间来解决,但没有任何效果。
问题已通过允许出站端口解决。不允许出站端口,因此无法连接请求。