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

标签 php curl port

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

当我 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 的响应。

请告诉我如何修复它。

提前致谢。

最佳答案

尝试这样设置端口:

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

或:

curl_setopt($ch, CURLOPT_PORT, 8088);

关于php - 无法使用端口号发出 php curl 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7188988/

相关文章:

php - Erlang Cowboy可以搭建PHP框架吗?

php - 如何修复 "Fatal error: Maximum execution time of 30 seconds exceeded"

php - 运行不断更新的脚本

php - CURL导入字符编码问题

php - 如何将元素信息发送到paypal?

java - 在两个不同的端口上运行 Tomcat 服务器

php - 多对多没有给出结果

curl - axios:在 axios 中传递 curl 的 -d

networking - Nginx-错误 : bind() to 0. 0.0.0 :80 failed. 权限被拒绝

port - 我的 Asterisk 软件在哪个端口上运行