Vscode-restclient: Connection is being rejected for localhost

Created on 12 Feb 2020  路  32Comments  路  Source: Huachao/vscode-restclient

Expectation: If I specify "localhost" in the host address the request should not change to "127.0.0.1".

Some web servers (in this case II Express) do not recognize 127.0.0.1. The server gets the request but is not be able to map against the correct web application.

Symptom:

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

See also #122

Steps to Reproduce:

  1. Run a web app from Visual Studio using IIS Express and http
  2. Any REST Client request to localhost will get the response ECONNREFUSED 127.0.0.1
  • VSCode Version: 1.42.0
  • OS Version: Windows 10
  • REST Client Version: 0.23.1
  • Visual Studio Version: 16.4.3 with a .NET Core 2.2 web app

2020-02-12 13_47_05-Home page - WebApplication1

question

Most helpful comment

@Hatgor as for your case, the added additional double quotes around the URL, removing it should work.

All 32 comments

I have a similar behavior using REST Client with PHP (Slim Framework). It "worked" before (version _0.22.2_), but doesn't anymore (versions _0.23.0_ and _0.23.1_).

After I start the server using php -S localhost:8080 -t src/, I also get:

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

But this "worked" like this before. The difference is that now, once I start the server using php -S 127.0.01:8080 -t src/, I always get a 401 when trying to send a request from REST Client even though it works from my Ionic/Angular application and also after entering the URL directly in the browser.

  • Version: 1.42.1
  • Commit: c47d83b293181d9be64f27ff093689e8e7aed054
  • Date: 2020-02-11T14:44:27.652Z
  • Electron: 6.1.6
  • Chrome: 76.0.3809.146
  • Node.js: 12.4.0
  • V8: 7.6.303.31-electron.0
  • OS: Darwin x64 19.3.0

@Bilosista What's your auth, why will you get 401? Do you mean you can work with localhost in version 0.22.2 or with 127.0.0.1

@Huachao It鈥檚 Basic auth. No idea why, I can try to check tomorrow (I鈥檓 using tuupola/slim-basic-auth), but it works fine when started using 127.0.0.1 with _0.22.2_, but doesn鈥檛 with _0.23.0_ nor _0.23.1_. Did something change in _0.23.0_?

@Bilosista I switched my underlying http client package from request to got, as well as some other changes. Can you show me your actual request, especially the line of Authorization header. BTW, if available, please also paste the 401 response details.

@Huachao Sure, here you go...

The request (I also tried with Authorization: Basic QWRtaW46aGVzbG8=):

GET http://localhost:8080/api/heslo/heslo
Authorization: Basic Admin heslo

The 401 response (using version _0.23.1_):

HTTP/1.1 401 Unauthorized
Host: localhost:8080
Date: Mon, 17 Feb 2020 08:25:03 GMT
Connection: close
X-Powered-By: PHP/7.3.11
Authorization: Basic QWRtaW46aGVzbG8=
WWW-Authenticate: Basic realm="Protected"
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Powered-By, X-Requested-With, Content-Type, Accept, Origin, Authorization
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS
Content-type: text/html; charset=UTF-8

The correct response (using _0.22.2_):

HTTP/1.1 200 OK
Host: localhost:8080
Date: Mon, 17 Feb 2020 08:30:20 GMT
Connection: close
X-Powered-By: PHP/7.3.11
Authorization: Basic QWRtaW46aGVzbG8=
Content-Type: application/json; charset=utf-8
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Powered-By, X-Requested-With, Content-Type, Accept, Origin, Authorization
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS

{
"heslo": "heslo",
"hash": "$2y$10$egJwZRiT958V0isuxEczG.ToT9Un5kk8d3rk4r3AZpxsElKLVsXc6"
}

@Bilosista It seems that I didn't handle the auth challenge case, I will update my code

@Bilosista can you try this version, and you need to manually remove the .txt in the file name, and install it in the Extensions tab of VSCode by clicking ..., and select Install From VSIX
rest-client-0.23.1.vsix.txt

@Huachao Yeah, it works ;)

I have same problem on macOs Catalina 10.15.3 with version 0.23.2

and curl from vscode
Screenshot 2020-04-27 at 17 32 40

curl from command line

鈺扳攢$ curl -H "Content-Type: application/json" --request POST -d '{"name":"Joe Doe"}' --url "http://localhost:8000" ; echo $?
0

@vaclavbenes can you work with tools like Postman and curl?

@Huachao. Yes I can. Problem is not in curl or Postman. They work fine.
I thought its related to firewall, but i can send POST from curl or postman . I ve tried different versions of client. its same behaviour.

btw: same on Arch Linux.

@vaclavbenes how can I setup a test environment like you?

vscode version
Version: 1.45.0-insider
Commit: abb4a35cfc26102f93fd00df7b59ce1a19c2017a
Date: 2020-04-28T05:34:21.109Z (5 hrs ago)
Electron: 7.2.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 19.3.0

my server

import { Drash } from "https://deno.land/x/[email protected]/mod.ts";

const docker = {
  image: "localtestimagecentos:latest",
  server: "http://192.168.1.104:8080",
  user: "device",
  verifications: 0,
};

class HomeResource extends Drash.Http.Resource {
  static paths = ["/"];
  public GET() {
    this.response.body = JSON.stringify(docker);
    return this.response;
  }

  public POST() {
    const image = this.request.getBodyParam("name");

    if (!image) {
      throw new Drash.Exceptions.HttpException(
        400,
        "This resource requires the `image` body param.",
      );
    }

    console.log(image);

    return this.response;
  }
}

const server = new Drash.Http.Server({
  response_output: "text/html",
  resources: [HomeResource],
});

const hostname = "localhost";
const port = 8000;

console.log(`http://${hostname}:${port}`);

server.run({
  hostname: hostname,
  port: port,
});

install deno https://deno.land/
run with deno -A example.ts

curl command

curl -H "Content-Type: application/json" --request POST -d '{"name":"Joe Doe"}' --url "http://localhost:8000"

@vaclavbenes I can't repro with your deno example, can you check your settings in VSCode like http.proxy?

@Huachao its strange , i removed all settings from user-settings and its no working.

I did progress. Plugin works with node-js express example, but not working with deno server example. Maybe its related to https://github.com/drashland/deno-drash

Has similar issue with my node-js express app.
My OS is Windows 10,
REST Client version is 0.23.2

Server is hosted on localhost:3000

Test request is
@url = "http://localhost:3000/"
GET {{url}}

Error message:

Connection is being rejected. The service isn鈥檛 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.

Postman face no such issues.

@Hatgor as for your case, the added additional double quotes around the URL, removing it should work.

@Hatgor as for your case, the added additional double quotes around the URL, removing it should work.

Thanks! It's working now =)

Im facing the same issue in MacOs Catalina

I have the same problem also.

The URL is defined as

https://localhost:44391/.well-known/openid-configuration
And the error is on
https://127.0.0.1:44391/.well-known/openid-configuration

Do you know why the localhost is replaced with 127.0.0.1 IP address. The IISExpress is only listening on localhost by name

It's on windows 10 2004 VS Code

Hi, I also have the same problem when trying use POST request on localhost. a GET request on a production url is fine. Just POST request on localhost is causing a problem for me.

I created a .txt file I called rest-client.txt. When I read this thread, I tried to install via vsix, and the file was not recognized. Neither were any other ones on my computer. What could I be doing wrong? Thanks in advance for any help you might be able to provide me! I'm on version 0.24.2.

I tried again, and now everything for some reason is working. My file is still called rest-client.txt by the way. Now the trick will be to reproduce this!

Hi, again, so far I have been able to and am starting to get how this works. It's actually much better using this extension that works directly with the code you are building instead of mock third party service code. Thanks!

Hi again,

Now everything works exactly as expected when I use req.body in my index.js (server file) for my Node.js/Express/MongoDB application. One thing that was causing issues but I didn't check at first was that I would get disconnected from the server and that is why things ended up not working. Now I just have to double check before I hit "Send Request". That must be something either with nodemon or VS Code itself. Thanks!

@Hatgor as for your case, the added additional double quotes around the URL, removing it should work.

thanks

@Bilosista can you try this version, and you need to manually remove the .txt in the file name, and install it in the Extensions tab of VSCode by clicking ..., and select Install From VSIX
rest-client-0.23.1.vsix.txt

can't sent any curl request on version 0.24.2. downgrade to 0.23.1 anything goes well.

I am confirming the double quotes would cause the problem. Just simply remove it and everything goes well.

@Huachao I am facing this issue.
error

My request is :-
POST http://localhost:8091/api/provider/token HTTP/1.1
Content-Type: application/json
Authorization: Basic XXXXXXXXXXXXXX

I am sending this request via VS code.

@Hatgor as for your case, the added additional double quotes around the URL, removing it should work.

This works for me.

Either declare variable like this without quotes
image

or write request url like
image

Found same issue via tomcat 9.0.45. My tomcat cannot be accessed via http://127.0.0.1:8080锛宐ut localhost:8080 is good.
is rest-client converting localhost to 127.0.0.1?

my request is:

###
# @name echo
GET http://localhost:8080/sms/api/echo
Content-Type: application/json;

The error is

The connection was rejected. Either the requested service isn鈥檛 running on the requested server/port, the proxy settings in vscode are misconfigured, or a firewall is blocking requests. Details: RequestError: connect ECONNREFUSED 127.0.0.1:8080.

Found same issue via tomcat 9.0.45. My tomcat cannot be accessed via http://127.0.0.1:8080锛宐ut localhost:8080 is good.
is rest-client converting localhost to 127.0.0.1?

my request is:

###
# @name echo
GET http://localhost:8080/sms/api/echo
Content-Type: application/json;

The error is

The connection was rejected. Either the requested service isn鈥檛 running on the requested server/port, the proxy settings in vscode are misconfigured, or a firewall is blocking requests. Details: RequestError: connect ECONNREFUSED 127.0.0.1:8080.

Yeah, it looks like it's converting it to 127.0.0.1. I just changed my settings, so now my PHP server now runs on 127.0.0.1 IP and everything works fine.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Odonno picture Odonno  路  22Comments

jianwu picture jianwu  路  13Comments

Fed29 picture Fed29  路  13Comments

ben-foster-cko picture ben-foster-cko  路  19Comments

johnbeynon picture johnbeynon  路  23Comments