REST client proxy issue in VScode
Asked Answered
N

6

6

When using the REST client extension in VSCode eg.

Send Request
GET http://localhost:4200/dashboard

###

I get following 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:4200

How can I change my http-proxy to 4200 instead of 127.0.0.1:4200 ?

Nuisance answered 13/11, 2020 at 21:39 Comment(1)
It has nothing to do with the VSCode itself. It's that you're most probably using WSL2 and your client is not able to convert your localhost hostname into your WSL2 vm's IP address. One dirty quick solution is ip a | grep inet in your WSL2 and use its IP address instead of localhost in your request URLs, which is a bad idea since WSL2 IP address is not static (it will change). The other solution is using a client that is able to work for WSL2 users too (Postman as an example).Fascia
J
5

The solution that works for me, it's to change the server hostname with a string (hostname: "127.0.0.1").

Deno/TS/Rest client Extension vscode

app.ts

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

const server = new Drash.Http.Server({
  response_output: "application/json",
  resources: [Api],
});

server.run({
  hostname: "127.0.0.1", // Just here !
  port: 1854,
});

console.log("Server running...");

api.ts

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

export class Api extends Drash.Http.Resource {
  static paths = ["/"];
  public GET() {
    this.response.body = `Hello World! (on ${new Date()})`;
    return this.response;
  }
}

req.http

GET http://localhost:1854/ HTTP/1.1

OR

GET http://127.0.0.1:1854/ HTTP/1.1
Jagir answered 22/5, 2021 at 12:33 Comment(1)
Great answer. In my case, I was running Firebase Serve, which by default was using localhost, so I simply had to override it with "firebase serve --host 127.0.0.1 --port 5000"Diastase
T
1

For Windows users

Please check your hosts file(C:\Windows\System32\drivers\etc\hosts) and confirm these lines are not hashed out

#   127.0.0.1       localhost
#   ::1             localhost
  • remove the hashes to uncomment them and save the hosts file then rerun the api server

modify the running code

add the --host 127.0.0.1 flag when running the server

Tragopan answered 31/12, 2023 at 11:23 Comment(0)
N
0

enter image description hereIt later worked. I realised that the error was with the double quotes in the api.http file and by removing them it worked.

Nonbelligerent answered 3/10, 2023 at 10:48 Comment(1)
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.Haggard
W
0

Although this is an old post, I thought my solution might be useful to someone out there.

In my case, I was working on a WebApi project, and decided to test my endpoint using Rest Client. I created a abc.http file for this purpose.

Firstly, my server wasn't running in VSCode. To start it, I went to run and debug and hit the play button.

When I clicked the Send Request button, I saw the detailed error, which pointed to the type I used in one of my models.

System.NotSupportedException: Serialization and deserialization of 'System.DateOnly' instances are not supported...

I recalled that I had defined a property in my model with the DateOnly type.

Steps taken to fix issue:

  1. Change type from DateOnly to DateTime
  2. Stop and start server (restart didn't work for me).
  3. Click the Send Request button again.

Done!

Whiney answered 11/11, 2023 at 7:51 Comment(0)
P
0

*****In Angular 17

Create a page javascript like server.js

const jsonServer = require('json-server')
const auth = require('json-server-auth')
const app = jsonServer.create()
const router = jsonServer.router('user_db.json')
// /!\ Bind the router db to the app
app.db = router.db
// You must apply the auth middleware before the router
app.use(auth)
app.use(router)
app.listen(4200)

Execute the commande node server.js and execute your file .http or .rest by clicking send request


GET http://localhost:4200/dashboard

The resource : https://www.npmjs.com/package/json-server-auth?activeTab=readme

Pilotage answered 21/4, 2024 at 18:24 Comment(0)
P
0

There are basic two ways

1.change directory: if the error was showing on current directory or folder ,then try to change them to another one and reload window

2.choose proper directory when you run program(*) : when you run dotnet program on terminal,then you choose proper directory where your current program is placed like

C:\Users\system_name\Desktop\Parent_directory>cd api_name.api

C:\Users\system_name\Desktop\Parent_directory>cd api_name.api>dotnet run
Building...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:<port_no>
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\system_name\Desktop\Parent_directory>cd api_name.api
Pecuniary answered 17/9, 2024 at 13:56 Comment(1)
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.Haggard

© 2022 - 2025 — McMap. All rights reserved.