首页 > 解决方案 > 如何在 Angular 中使用 HttpClient 访问传入消息对象?

问题描述

我正在从我的 Angular 文件向服务器发送以下请求。可以从我的打字稿文件(最好使用 HttpClient 对象)中访问它吗?

IncomingMessage {

  ...

  headers: {

    host: 'localhost:8080',

    connection: 'keep-alive',

    accept: 'application/json, text/plain, */*',

    'content-type': 'application/json',

    'sec-fetch-site': 'same-origin',

    'sec-fetch-mode': 'cors',

    'accept-encoding': 'gzip, deflate, br',

    'accept-language': 'en-US,en;q=0.9',

    cookie: '_iAToken=<cookie>'

  },

  ...

  url: '/teradata/databases/view/djfg',

  method: 'GET',

  baseUrl: '/api',

  originalUrl: '/api/teradata/databases/view/djfg',

  params: { '0': 'teradata/databases/view/djfg' },

  secret: '<secret>',

  cookies: {},

  signedCookies: [Object: null prototype] {

    _iAToken: '<token>'

  },

  _parsedOriginalUrl: Url {

    protocol: null,

    slashes: null,

    auth: null,

    host: null,

    port: null,

    hostname: null,

    hash: null,

    search: null,

    query: null,

    pathname: '/api/teradata/databases/view/djfg',

    path: '/api/teradata/databases/view/djfg',

    href: '/api/teradata/databases/view/djfg',

    _raw: '/api/teradata/databases/view/djfg'

  },

  session: Session {

    cookie: {

      path: '/',

      _expires: 2021-08-29T22:01:49.960Z,

      originalMaxAge: 544320000,

      httpOnly: true,

      secure: true

    },

    accessToken: '<access_token>',

    tokenset: {

      access_token: '<access_token>',

      token_type: 'Bearer',

      expires_at: 1629737347

    }

  },

}

我正在后端调用 API,并且我想检查在我进行调用时是否正在发送此消息。所以,我想知道它是否可以使用 HttpClient 对象访问。

标签: javascriptangulartypescripthttprequestrest

解决方案


如果您只是想查看请求和响应,Chrome DevTools Network 选项卡将为您提供所有这些信息。发出请求时,必须打开 DevTools。


推荐阅读