网址请求被拒绝

时间:2019-05-30 11:29:12

标签: php apache javascript centos

我无法使url请求在Centos7(使用Apache)上正常工作。我准备了一些简单的Java脚本-> php请求示例来介绍我的问题:

file1.html:

<script type="application/javascript"> 
$(document).ready(function() {
    var xhr = new XMLHttpRequest();
    var url = "http://127.0.0.1:4040/file2.php";
        xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            console.log(xhr.responseText);
        }
    };
    var data = JSON.stringify({"email": "hey@mail.com", "password": "101010"});
    xhr.send(data);
}); 
</script>

fille2.php:

<?php 
$received_json = file_get_contents('php://input');  
$received_json = json_decode($received_json);  
echo($received_json->email);
?>

虚拟主机设置:

<VirtualHost 127.0.0.1:4040>

    DocumentRoot "my_path/........"

    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
    Header set Access-Control-Max-Age "1000"
    Header set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-t$

 <Directory "my_path/.............">
        Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>

</VirtualHost>

以上脚本在我的本地Windows环境中正常工作。

我到目前为止所做的测试:

  1. iptables和防火墙已关闭

  2. 已禁用SELinux

  3. file1.html或file2.php中没有sytanx错误

  4. 命令:

    netstat -ant | grep -w 4040
    

    输出:

    tcp        0      0 127.0.0.1:4040          0.0.0.0:*               
    LISTEN
    
  5. 命令:

    wget 127.0.0.1:4040/file1.html
    

    输出:

    Connecting to 127.0.0.1:4040... connected.
    HTTP request sent, awaiting response... 200 OK
    
  6. 当我在网络浏览器中运行 file1.html 时,出现以下错误:OPTIONS http://127.0.0.1:4040/file2.php net::ERR_CONNECTION_REFUSED

  7. “拒绝连接”错误仅在我的Java脚本-> php url请求(用户端->服务器端)中发生。

有人遇到类似的问题吗?你能给点建议吗?

0 个答案:

没有答案