NodeJS VScode中的REST客户端代理问题

8oomwypt  于 4个月前  发布在  Node.js
关注(0)|答案(4)|浏览(73)

当在VSCode中使用REST客户端扩展时,

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

###

字符串
我得到以下错误:

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


如何将我的http代理服务器更改为4200而不是127.0.0.1:4200?

35g0bw71

35g0bw711#

对我来说,解决方案是用字符串(hostname:“127.0.0.1“)更改服务器主机名。

Deno/TS/Rest客户端扩展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;
  }
}

  • 请求http*
GET http://localhost:1854/ HTTP/1.1


GET http://127.0.0.1:1854/ HTTP/1.1

brgchamk

brgchamk2#

enter image description here后来它工作了。我意识到错误是在API.http文件中的双引号,通过删除它们,它工作了。

wgmfuz8q

wgmfuz8q3#

虽然这是一个老帖子,但我认为我的解决方案可能对外面的人有用。
在我的例子中,我正在做一个WebApi项目,并决定使用Rest Client测试我的端点。我为此创建了一个**abc.http文件。
首先,我的服务器没有在VSCode中运行。为了启动它,我去了
run and debug并点击了play按钮。
当我点击
Send Request**按钮时,我看到了详细的错误,它指向我在一个模型中使用的类型。

System.NotSupportedException:不支持“System.DateOnly”示例的序列化和反序列化.

我记得我在模型中定义了一个属性,类型为**DateOnly
解决问题所采取的步骤:
1.将类型从
DateOnly更改为DateTime**
1.停止并启动服务器(重新启动对我不起作用)。
1.再次点击**Send Request**按钮。
搞定了!

brgchamk

brgchamk4#

Windows用户

  • 请检查您的主机文件(C:\Windows\System32\drivers\etc\hosts),并确认这些行没有散列 *
#   127.0.0.1       localhost
#   ::1             localhost

字符串

  • 删除散列以取消注解,然后保存主机文件,然后禁用API服务器

修改运行代码

在运行服务器时添加--host 127.0.0.1标志

相关问题