Url requests refused

Issues related to configuring your network
Post Reply
kryszen2
Posts: 6
Joined: 2019/05/09 13:37:37

Url requests refused

Post by kryszen2 » 2019/05/26 10:54:56

Hello.

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": "hey@mail.com", "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
output:
http://127.0.0.1:4040/
Connecting to 127.0.0.1:4040... connected.
HTTP request sent, awaiting response... 200 OK

6. command:
wget 127.0.0.1:4040/file1.html
output:
ftp://127.0.0.1/4040:file1.html
=> '4040:file1.html'
Connecting to 127.0.0.1:21... failed: Connection refused.

7. 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

8. ‘connection refused’ errors occur only in my java script -> php url requests (user side ->server side).




Does anyone met similar problem? Could you please give some advice.

User avatar
TrevorH
Forum Moderator
Posts: 26557
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Url requests refused

Post by TrevorH » 2019/05/26 12:04:59

6. command:
wget 127.0.0.1:4040/file1.html
output:
ftp://127.0.0.1/4040:file1.html
=> '4040:file1.html'
Connecting to 127.0.0.1:21... failed: Connection refused.
I'd be pretty sure you had a typo in your wget in real life that you did not reproduce in your forum post. Spot the typo in the message that wget returned to you: ftp://127.0.0.1/4040:file1.html
CentOS 5 died in March 2017 - migrate NOW!
CentOS 6 goes EOL sooner rather than later, get upgrading!
Full time Geek, part time moderator. Use the FAQ Luke

kryszen2
Posts: 6
Joined: 2019/05/09 13:37:37

Re: Url requests refused

Post by kryszen2 » 2019/05/27 08:49:06

Thank you for the answer. Yes, you are right - there was a typo in wget 127.0.0.1:4040/file1.html.

Now the wget command outputs:
Connecting to 127.0.0.1:4040... connected.
HTTP request sent, awaiting response... 200 OK


Unfortunatelly I'm still stuck with error: OPTIONS http://127.0.0.1:4040/file2.php net::ERR_CONNECTION_REFUSED when try to run file1.html in web browser.

Do you have any ideas how to check where the problem resides?

Post Reply

Return to “CentOS 7 - Networking Support”