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

2022-08-31 00:03:41

我无法用端口号发出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 的响应。

请让我知道如何解决它。

提前。


答案 1

尝试像这样设置端口:

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

艺术

curl_setopt($ch, CURLOPT_PORT, 8088);

答案 2

尝试设置

curl_setopt($ch,CURLOPT_PORT, 8088);

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


推荐