<small id='18SNa'></small><noframes id='18SNa'>

    <tfoot id='18SNa'></tfoot>

      • <bdo id='18SNa'></bdo><ul id='18SNa'></ul>

    1. <legend id='18SNa'><style id='18SNa'><dir id='18SNa'><q id='18SNa'></q></dir></style></legend>

      <i id='18SNa'><tr id='18SNa'><dt id='18SNa'><q id='18SNa'><span id='18SNa'><b id='18SNa'><form id='18SNa'><ins id='18SNa'></ins><ul id='18SNa'></ul><sub id='18SNa'></sub></form><legend id='18SNa'></legend><bdo id='18SNa'><pre id='18SNa'><center id='18SNa'></center></pre></bdo></b><th id='18SNa'></th></span></q></dt></tr></i><div id='18SNa'><tfoot id='18SNa'></tfoot><dl id='18SNa'><fieldset id='18SNa'></fieldset></dl></div>
    2. php cURL 到 localhost 返回在开放端口上被拒绝的权限

      php cURL to localhost returns permission denied on an open port(php cURL 到 localhost 返回在开放端口上被拒绝的权限)
    3. <small id='BmcHt'></small><noframes id='BmcHt'>

      <legend id='BmcHt'><style id='BmcHt'><dir id='BmcHt'><q id='BmcHt'></q></dir></style></legend>
          <i id='BmcHt'><tr id='BmcHt'><dt id='BmcHt'><q id='BmcHt'><span id='BmcHt'><b id='BmcHt'><form id='BmcHt'><ins id='BmcHt'></ins><ul id='BmcHt'></ul><sub id='BmcHt'></sub></form><legend id='BmcHt'></legend><bdo id='BmcHt'><pre id='BmcHt'><center id='BmcHt'></center></pre></bdo></b><th id='BmcHt'></th></span></q></dt></tr></i><div id='BmcHt'><tfoot id='BmcHt'></tfoot><dl id='BmcHt'><fieldset id='BmcHt'></fieldset></dl></div>

          <tfoot id='BmcHt'></tfoot>
              <tbody id='BmcHt'></tbody>

              • <bdo id='BmcHt'></bdo><ul id='BmcHt'></ul>
                本文介绍了php cURL 到 localhost 返回在开放端口上被拒绝的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在尝试使用 php cURL 库向端口 4321 上的 localhost 发出 cURL 请求时遇到权限被拒绝错误.希望这对于以前遇到此问题的人来说非常容易或明显.

                I'm getting a permission denied error when trying to make a cURL request with the php cURL library to localhost on port 4321. This will hopefully be really easy or obvious for someone who's run into this before.

                我能够从局域网上的另一个系统向生产服务器发出相同的 cURL 请求.例如,如果在局域网上的另一个系统上,我使用下面的函数发出请求,其中 $host='http://192.168.1.100:4321' 则一切正常.如果我在 $host='http://localhost:4321'$host='http://127.0.0.1:4321'$host='::1:4321' 然后我收到Permission Denied"的 cURL 错误

                I'm able to make the identical cURL request from another system on the local area network to the production server. For example, if on another system on the local area network I make a request using the function below where $host='http://192.168.1.100:4321' then everything works exactly like it should. If I run on the system itself where $host='http://localhost:4321' or $host='http://127.0.0.1:4321' or $host='::1:4321' then I get a cURL error of "Permission Denied"

                我为我非常简单的请求编写的函数是:

                The function I wrote for my very simple request is:

                function makeRequest($host,$data){
                    $ch = curl_init();
                    curl_setopt($ch,CURLOPT_URL, $host);
                    curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                    $result = json_decode(curl_exec($ch),true);
                    if(!empty(curl_error($ch))){
                        $result = print_r(curl_error($ch).' - '.$host);
                    }
                    curl_close($ch);
                    return $result;
                }
                

                系统是一个centos 7服务器.运行 firewall-cmd --list-all 显示我的开放端口

                The system is a centos 7 server. Running firewall-cmd --list-all shows my open ports

                端口:443/tcp 80/tcp 4321/tcp

                如果您有任何想法,或者需要我检查设置,请随时询问.

                If you have some idea, or need me to check a setting don't hesitate to ask.

                编辑主机文件看起来像

                127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
                

                EDIT2

                当我对同一个端口使用命令行 curl 时,一切都会恢复正常.

                When I use commandline curl against the same port everything comes back alight.

                 /]$ curl -v localhost:4321
                * About to connect() to localhost port 4321 (#0)
                *   Trying ::1...
                * Connected to localhost (::1) port 4321 (#0)
                > GET / HTTP/1.1
                > User-Agent: curl/7.29.0
                > Host: localhost:4321
                > Accept: */*
                >
                < HTTP/1.1 200 OK
                < Accept-Ranges: bytes
                < Cache-Control: no-cache, no-store, must-revalidate
                < Content-Length: 774....
                

                推荐答案

                我在以下位置找到了问题的答案:使用 Curl 发布 xml 时获取权限被拒绝?

                I found the answer to the problem at: Getting permission denied while Posting xml using Curl?

                问题是SELinux,解决方法是运行:

                The problem is SELinux and the solution is to run:

                sudo setsebool httpd_can_network_connect 1
                

                我可以使用 php cURL 库访问世界上所有其他网站,但不能使用不同端口上的 localhost,而我能够从命令行 cURL 访问 localhost,这对我来说没有任何意义.

                It doesn't make sense to me that I could use the php cURL library to access every other website in the world, but not localhost on a different port, while I was able to access the localhost from command line cURL.

                这篇关于php cURL 到 localhost 返回在开放端口上被拒绝的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Converting string to MySQL timestamp format in php(在php中将字符串转换为MySQL时间戳格式)
                datetime to timestamp(日期时间到时间戳)
                PHP timestamp date to user timezone(PHP时间戳日期到用户时区)
                Converting TIMESTAMP to unix time in PHP?(在 PHP 中将 TIMESTAMP 转换为 unix 时间?)
                Convert ISO 8601 to unixtimestamp(将 ISO 8601 转换为 unixtimestamp)
                Finding days between 2 unix timestamps in php(在php中查找2个unix时间戳之间的天数)
                <tfoot id='y9Nv7'></tfoot>
                    <tbody id='y9Nv7'></tbody>
                  • <small id='y9Nv7'></small><noframes id='y9Nv7'>

                    • <bdo id='y9Nv7'></bdo><ul id='y9Nv7'></ul>

                      <i id='y9Nv7'><tr id='y9Nv7'><dt id='y9Nv7'><q id='y9Nv7'><span id='y9Nv7'><b id='y9Nv7'><form id='y9Nv7'><ins id='y9Nv7'></ins><ul id='y9Nv7'></ul><sub id='y9Nv7'></sub></form><legend id='y9Nv7'></legend><bdo id='y9Nv7'><pre id='y9Nv7'><center id='y9Nv7'></center></pre></bdo></b><th id='y9Nv7'></th></span></q></dt></tr></i><div id='y9Nv7'><tfoot id='y9Nv7'></tfoot><dl id='y9Nv7'><fieldset id='y9Nv7'></fieldset></dl></div>

                        <legend id='y9Nv7'><style id='y9Nv7'><dir id='y9Nv7'><q id='y9Nv7'></q></dir></style></legend>