vscode-restclient
vscode-restclient copied to clipboard
Connection is being rejected for localhost
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’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:63353.
See also #122
Steps to Reproduce:
- Run a web app from Visual Studio using IIS Express and http
- 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
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’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: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’s Basic auth. No idea why, I can try to check tomorrow (I’m using tuupola/slim-basic-auth
), but it works fine when started using 127.0.0.1 with 0.22.2, but doesn’t 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
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’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.
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 selectInstall 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.
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
or write request url like
Found same issue via tomcat 9.0.45. My tomcat cannot be accessed via http://127.0.0.1:8080
,but 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’t 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
,butlocalhost:8080
is good. is rest-client convertinglocalhost
to127.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’t 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.
Found same issue via tomcat 9.0.45. My tomcat cannot be accessed via
http://127.0.0.1:8080
,butlocalhost:8080
is good. is rest-client convertinglocalhost
to127.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’t 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.
how did you change it ?
For those who waste a whole day trying to find the solution that you think that is a problem with node, or IIS Express, etc. The problem for me was related with this: https://stackoverflow.com/questions/34543443/cant-access-127-0-0-1
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’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:63353.
See also #122
Steps to Reproduce:
- Run a web app from Visual Studio using IIS Express and http
- 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
are you running under WSL? I had similar problem and everything worked with CMD https://stackoverflow.com/questions/64763147/access-a-localhost-running-in-windows-from-inside-wsl2
its not sending the Authorization header for local host url, when I tried to send Authorization header for a lamda gate-way url its working fine, But when i try to send Authoriation header for localhost url its nor working getting 401 Authorization header not included
the solution was very simple for me. after building the server file, i forgot to run nodejs or nodemone to start/refresh the server. you simply need to initate it before posting requests
Spent all day trying to solve this issue but can't seem to get around it issue. Background: I ran my app in WSL2 environment. On my host machine, I can reach it with "localhost:3000", but "127.0.0.1:3000" will not reach it. It has something to do with WSL2 mapping "localhost" to VM processes but not 127.0.0.1.
Is there a way we can prevent REST Client from converting "localhost" into "127.0.0.1"?
Answering my own question. I found a solution for my use case. Basically, I run another instance of VisualStudio Code within WSL2 environment.
- Open WSL2 (I'm using ubuntu 20.04),
- Type
code .
this will install a copy of Visual Studio Code, open VSC in the directory. - Visual Studio Code window will pop up on the desktop.
- Install this REST Client
- Create a .rest file
- With "localhost"or "127.0.0.1"will reach my service.
Im using node server. add this setting to vs code settings.json worked for me : "http.proxy": "https://127.0.0.1:YOUR_SERVER_PORT"
@S-STALWART-S
My environment is fully working within WSL2, but still want to try other suggestions. I have add the "http.proxy" in settings.json, but I have no idea how to get it to work. Will look into that in future. It's good to know there is alternate solution.
I somehow fixed it. @kimcatsb is completely right. The issue will be fixed for WSL2 users if this extension stops turning localhost
into 127.0.0.1
. When localhost turns into 127.0.0.1, it will point to the actual Windows OS, i.e., the WSL2's host, and not the WSL2 vm itself.
There are multiple solutions to this. The quickest one is, run ip a | grep inet
in WSL2 and use its actual IP address. So your requests will become something this:
GET http://172.18.228.135:3000/api/foo
However, this solution isn't great as WSL2's IP address is not static (it will change). Another solution would be using Windows cmd which is a nightmare for many unixy people. So I also ask @Huachao to fix this issue for WSL2 users. Thanks.
only run the application in your terminal 🤷♂️