我无法使用端口号进行php curl请求,没有端口号我正在得到正确的响应。
通过终端,当我卷曲http://www.sample.com:8088时,我正在得到正确的回复。但不是通过php curl做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给出响应。
请告诉我如何修复它。
提前谢谢。
答案 0 :(得分:23)
尝试像这样设置端口:
curl_setopt($ch, CURLOPT_PORT, $_SERVER['SERVER_PORT']);
或:
curl_setopt($ch, CURLOPT_PORT, 8088);
答案 1 :(得分:8)
答案 2 :(得分:3)
答案 3 :(得分:2)
确保在Cent OS中启用端口8080
并尝试此curl_setopt($ch, CURLOPT_PORT, 8088);
答案 4 :(得分:2)
我带着这个问题去了服务器管理员,他在centos中更改了配置
在文件夹/ etc / sysconfig /
中他编辑了文件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
我的问题解决了。
答案 5 :(得分:1)
“setsebool httpd_can_network_connect on”解决了我的问题