+ 1

How to make "get" request to local express server ?

So i am trying to do the above and always get connection refused , what is actually happening here ? I can connect to google but not localhost !! If anyone can explain it in simple terms and as well tell any solution to it I will be really grateful to you . https://code.sololearn.com/c4QDCZaa3ouM/?ref=app Edit:server might not to be up for hours sometime, so let me know if you think you can help and i will start it again.

28th Feb 2021, 10:16 PM
Abhay
Abhay - avatar
4 Respostas
+ 2
"i can make requeat to google, why not localhost? " Because every machine that has networking capability has a localhost. localhost name is mapped to address 127.0.0.1 for IPv4 and ::1 for IPv6. When a machine makes request to localhost it's received by the very same machine. So when ypu make request from sololearn server to 127.0.0.1 the request is supposed to be handled by sololearn server and not any other machine. So if you manage to run express server and this python script on same machine the request will be successful. Google has reserved domain name for their use and it's mapped to a set of static public ip addresses where they can handle incoming requests. I hope it's clear now.
1st Mar 2021, 3:26 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 1
Of course, You can make HTTP request to server running on localhost. Make sure that you have started server and it's listening on same port you have made request to. About your edit... What do you mean by "server might not be up for hours sometime"? Are you trying to make request from sololearn to your localhost? Well, If yes then it'll not work. The localhost refers to current computers address. If you run code on sololearns server it'll refer to their server not your machine.
1st Mar 2021, 12:58 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 1
🇮🇳Omkar🕉 yes i am aware that i am making a request from sololearn server to localhost express server but i don't care about it , i can make request to google , why not localhost ? Anyway ty:) and i am running that server for experiment , can't keep it running when i am not using.
1st Mar 2021, 2:21 PM
Abhay
Abhay - avatar
+ 1
🇮🇳Omkar🕉 ty but i didn't get what you mean by "Google has reserved ... ", can't i handle requests at my localhost ? Or it has something to do with how sololearn server is configured to connect with addresses like google but not localhost and so i can't do anything about it!
1st Mar 2021, 3:36 PM
Abhay
Abhay - avatar