无法使用端口号发出 php curl 请求

发布于 2024-12-01 14:53:28 字数 1232 浏览 0 评论 0原文

我无法使用端口号发出 php curl 请求,如果没有端口号,我将得到正确的响应。

通过终端,当我执行curl http://www.sample.com:8088 时,我得到了正确的响应。但不是通过 phpcurl 执行curl_inf() 我收到

Array ( [url] => http://www.sample.com:8088/ [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => 0 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ( ) ) 

我的代码,

$url = "http://www.sample.com:8088/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, True);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
$report=curl_getinfo($ch);
print_r($report);
$result = curl_exec($ch);
curl_close($ch);
echo $result;

此代码给我来自 ubuntu 的响应,但如果指定了端口号,则不给 Cent os 响应。

请让我知道如何修复它。

提前致谢。

I am unable to make a php curl request with port number , without port number i am getting response properly.

Through terminal when i do curl http://www.sample.com:8088 i am getting response back properly. But not through php curl on doing curl_inf()
i am getting

Array ( [url] => http://www.sample.com:8088/ [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => 0 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ( ) ) 

My code

$url = "http://www.sample.com:8088/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, True);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
$report=curl_getinfo($ch);
print_r($report);
$result = curl_exec($ch);
curl_close($ch);
echo $result;

this code give me response from ubuntu , but not giving response from cent os if port number is specified.

Please let me know the how to fix it.

THanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

怎言笑 2024-12-08 14:53:28

尝试像这样设置端口:

curl_setopt($ch, CURLOPT_PORT, $_SERVER['SERVER_PORT']);

或:

curl_setopt($ch, CURLOPT_PORT, 8088);

Try to set the port like this:

curl_setopt($ch, CURLOPT_PORT, $_SERVER['SERVER_PORT']);

or:

curl_setopt($ch, CURLOPT_PORT, 8088);
此生挚爱伱 2024-12-08 14:53:28

尝试设置

curl_setopt($ch,CURLOPT_PORT, 8088);

查看更多信息 http://php.net/manual/en/function .curl-setopt.php

Try to set

curl_setopt($ch,CURLOPT_PORT, 8088);

See more info http://php.net/manual/en/function.curl-setopt.php

旧时模样 2024-12-08 14:53:28

添加

curl_setopt($ch, CURLOPT_PORT, 8088);

Curl_setopt 参考

Add

curl_setopt($ch, CURLOPT_PORT, 8088);

Curl_setopt reference

梦言归人 2024-12-08 14:53:28

“setsebool httpd_can_network_connect on”为我解决了这个问题

"setsebool httpd_can_network_connect on" resolves the problem for me

弥枳 2024-12-08 14:53:28

确保 Cent OS 中启用了端口 8080

并尝试这个 curl_setopt($ch, CURLOPT_PORT, 8088);

Make sure that the port 8080 is enabled in Cent OS

and try this curl_setopt($ch, CURLOPT_PORT, 8088);

倾城花音 2024-12-08 14:53:28

我带着这个问题去找服务器管理员,他

在文件夹 /etc/sysconfig/ 中

更改了 centos 中的配置,他编辑了文件 selinux 并更改了 SELINUX=disabled 并重述了它。

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled

我的问题得到了解决。

I went to server admin with this problem and he changed configuration in centos

in folder /etc/sysconfig/

he edited file selinux and change SELINUX=disabled and restated it.

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled

and my problem got solved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文