4

I'm using Thunder Client on Visual Studio Code, and tried making a request to "localhost:3000".

It gave me an error

Connection was refused by the server

Any fix to this?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Evee
  • 41
  • 1
  • 2

10 Answers10

14

Using SvelteKit, VSCode and Thunder Client

Example that didn't work for me: localhost:5173/api/posts

Solved by using [::1]:5173/api/posts

user21008103
  • 141
  • 1
  • 3
  • 3
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 15 '23 at 20:22
  • Any reason why this hack would work? I am facing the same issues in another extension called `REST Client`, `localhost`, and `127.0.0.1` doesn't work at all but `[::1]` gives some different error regarding `TLS`. – Visrut Mar 07 '23 at 15:49
  • I was facing the same connection refused issue on ThunderClient that got resolved when used `[::1]` in place of localhost, e.g., `http://[::1]:8000/api/` – Abhishek Kumar Apr 09 '23 at 05:09
1
  1. if you are using WSL on Windows use [::1] instead of localhost in the address bar. Example [::1]:3000/api/v1 .
  2. Another option is to use the PowerShell instead of the WSL terminal.
  3. You can also move your project directory to the Linux file system (~/home)
Sebastian Brosch
  • 42,106
  • 15
  • 72
  • 87
Cobby
  • 11
  • 2
1

You are facing this problem because of backend you juts have to start your backend and also make sure you have install body-parser

0

Please use your IP address instead of localhost: ipaddress:port.

Then, it might work. Eg. 192.168.0.1:3000

For more information see our support page comment

https://github.com/rangav/thunder-client-support/issues/251#issuecomment-874439967

But instead of using localhost:9000 I did use the actual IP set for the computer… 198.168.0.189:9000 for example, then it works.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Ranga Vadhineni
  • 349
  • 2
  • 13
  • Hello... I have this same issue but my endpoint is not a localhost endpoint. The server domain is an actual IP address internal to our company. Also, if I start a REST server locally and use the same endpoint with localhost... I have no issue actually. Only with the server on the network. Also it's not just this particular server, all my endpoints on the various servers have this same issue. Localhost no issue. The "solution" you propose in the link above does not apply nor work for my case. :( – Joseph Cozad Apr 13 '22 at 17:56
  • Joseph create an issue on our Thunder Client GitHub page, I will look into it. – Ranga Vadhineni May 24 '22 at 05:13
0

Using Django here and sending request to

127.0.0.1:8000/

instead of

localhost:8000/

works

momo668
  • 199
  • 3
  • 8
0

Make sure to use the FQDN with http:// instead of https://

That worked for me

Edward Casanova
  • 726
  • 7
  • 19
0

I think I may have found the solution (at least in Node/Express), indirectly thanks to Ranga Vadhineni's answer. Since I can't explain why this happens, I will just explain my train of thought on how I figured it out.

Connection was refused by the server.

Ugh, Thunder Client was again giving me trouble requesting to localhost, changing the request URL to 127.0.0.1 didn't help, tried to use my local IP with all that implies.

  1. Change the URL in Thunder to 192.168.0.10
  2. Enable the rule in Windows' firewall to allow incoming requests for Node.js
  3. Change my server's listening host from "localhost" to 0.0.0.0
  4. Voilà!

But... that didn't make much sense, and it's also a huge limitation, there has to be something going on. I tried changing Thunder's URL back to 127.0.0.1, and it worked... huh!? How about localhost? It worked! Eh!?

Rushed back to my serve's configuration and changed the host back to localhost. As expected this time, Thunder got a connection refused; keep in mind that both Postman and Insomia didn't have a problem with this, only Thunder! But then again Thunder reports the problem being on the server...

Instead of using localhost for my host in the server's configuration, I tried 127.0.0.1... voilà...

TL;DR

Thunder Client can handle both 127.0.0.1 and localhost in the URL with no problem, the issue seems to be (at least in Node/Express) in the server itself.

Simply change the server's host, so that instead of listening to localhost, it listens to 127.0.0.1.

If anybody can provide an explanation as to why this works, please do so, I'm at a lost here

0

When we open the Visual Studio Code, the remote access option is automatically activated.

Remote Windown

To work perfectly, it will depend on where your application is running. For example, if running directly on windows, close the remote vs code connection.

Click on the blue button

Then select the option "close remote connection".

Close Remote Windown

desertnaut
  • 57,590
  • 26
  • 140
  • 166
0

express validator

 routers.post('/',[
        body('name').isLength({min:3}),
        body('password').isLength({min:5}),
        body('email').isEmail(),
    ],(req,res)=>{
        const errors = validationResult(req);
        if (!errors.isEmpty()) {
          return res.status(400).json({ errors: errors.array() });
        }
    
        res.send(req.body); 
    
        
    })
desertnaut
  • 57,590
  • 26
  • 140
  • 166
0

To fix the issue you need to explicitly define the host name in package.json file.

"dev-server": "json-server --watch ./db.json -p 3200 -H 127.0.0.1"