首页 > 解决方案 > 打字稿http获取请求

问题描述

我正在尝试为使用 angular 2 的学校俱乐部编辑代码,我需要在 component.ts 文件中发出 http get 请求。我不需要从中获取任何信息,因为它只是向正在侦听请求的服务器发送请求。从谷歌搜索尝试了多种方法,但没有得到任何地方。

标签: angulartypescript

解决方案


HTTP 通过fetch()API获取

节点.js

节点本身没有fetch。安装node-fetch和使用它:

const fetch = require('node-fetch');

// in an async function...
await fetch('URL').then(res => res.text());

浏览器

这很简单:

// in an async function...
await fetch('URL').then(res => res.text());

推荐阅读