无法使用端口号发出 php curl 请求 [英] Unable to make php curl request with port number

查看:36
本文介绍了无法使用端口号发出 php curl 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

当我执行 curl 时通过终端 http://www.sample.com:8088 我得到正确回复.但不是通过 php curl 做 curl_inf()我得到了

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 ( ) ) 

我的代码

$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 的响应.

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

请告诉我如何修复它.

提前致谢.

推荐答案

尝试这样设置端口:

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

或:

curl_setopt($ch, CURLOPT_PORT, 8088);

这篇关于无法使用端口号发出 php curl 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆