I can’t make url requests work properly on Centos7 (with Apache). I’ve prepared some simple java script -> php request sample to present my problem :
file1.html:
Code: Select all
<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": "[email protected]", "password": "101010"});
xhr.send(data);
});
</script>
fille2.php:
Code: Select all
<?php
$received_json = file_get_contents('php://input');
$received_json = json_decode($received_json);
echo($received_json->email);
?>
vhost settings:
Code: Select all
<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>
The above scripts work fine in my local Windows environment.
tests I’ve made so far:
1. iptables and firewalled turned off
2. SELinux disabled
3. no sytanx errors in file1.html nor file2.php
4. command:
netstat -ant | grep -w 4040
output:
tcp 0 0 127.0.0.1:4040 0.0.0.0:* LISTEN
5. command:
wget 127.0.0.1:4040/file1.html
output:
Connecting to 127.0.0.1:4040... connected.
HTTP request sent, awaiting response... 200 OK
6. When I run file1.html in web browsers, the following error shows up:
OPTIONS http://127.0.0.1:4040/file2.php net::ERR_CONNECTION_REFUSED
7. ‘connection refused’ errors occur only in my java script -> php url requests (user side ->server side).
Did anyone meet similar problem? Could you please give some advice.