vscode-restclient: Connection is being rejected

  • VSCode Version: Version 1.17.2 (1.17.2)
  • OS Version: MacOS Sierra 10.12.4 (16E195)
  • REST Client Version: Latest

Steps to Reproduce:

Try and send request

POST /api HTTP/1.1
Host: testapp.com
Content-Type: application/json
Accept: application/json
Cache-Control: no-cache

{
	"name": "smith"
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 23 (7 by maintainers)

Commits related to this issue

Most upvoted comments

For people using Express.js, I resolved this issue by specifying the host with app.listen():

app.listen(8080, 'localhost')

It’s strange because I had been using REST client for weeks without issues and without specifying localhost.

I had the same problem, but I realized that I have been request the url as a ‘string’ and you should not. No quotations and it works.

Using Windows 10 I had the same issue.

My local server (Lumen) was running on localhost:8080, I set the request as below:

POST http://localhost:8080 content-type: application/json

{ “name”: “sample”, “time”: “Wed, 21 Oct 2015 18:27:50 GMT” }

And got the error Connection is being rejected.

I suspect this is not directly related to vscode-restclient but the way how localhost is now handled in Windows 10.

To fix this I just ran my Lumen server as 127.0.0.1:8080 instead of localhost:8080, all worked after that.

Hope this help someone in the future.

Thanks for pointing that out. I had just wrong http settings. All good now.

If you look at your browser request headers, you might see that the host the browser uses even if you point the address bar to localhost is not the IPv4 format of 127.0.0.1, but IPv6: [::1].

Effectively this is the same as localhost.

For me, a bare bones SvelteKit app with a single route added didn’t work from REST Client like this:

GET http://localhost:5173/test HTTP/1.1

but worked immediately when I switched to this:

GET http://[::1]:5173/test HTTP/1.1

Digging deeper, I noticed that the hosts file on Win 11 now no longer specifies the IP address for localhost, with a mention that it is now handled by DNS.

# localhost name resolution is handled within DNS itself.
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10  x.acme.com     # x client host
# 127.0.0.1    localhost
# ::1          localhost

I would have uncommented the line with 127.0.0.1 and test again but I think this requires a reboot and I’m fine with [::1]. Besides, I think this is a security measure anyway.

I’m getting the same behavior with a Lumen server running trough php -S localhost:8000 -t public on Windows 10. Solved it by using php -S 127.0.0.1:8000 -t public. Postman had not problems with it. I suspect the underlying node package that sends the request is the culprit because I tried another rest client extension and got errors there as well.

Hi I am also getting the below error

Connection is being rejected. The service isn’t running on the server, or incorrect proxy settings in vscode, or a firewall is blocking requests. Details: RequestError: connect ECONNREFUSED 127.0.0.1:443.

How do i check for rest client related settings in vscode setting file

@kuncevic can you show me you rest client related settings in vscode setting file?

@brokenthorn thanks for this! Indeed the extension always fails on Windows 11 when using localhost. Your solution worked for me. Perhaps it would be great if author fixes this in the documentation.

I’m also getting this error in-case of a simple GET request which works well in browser.

Connection is being rejected. The service isn’t running on the server, or incorrect proxy settings in vscode, or a firewall is blocking requests. Details: Error: connect ECONNREFUSED