在 Nestjs 中发送带有 headers 的 Post 请求

Tin*_*iwa 0 request node.js express typescript nestjs

我正在尝试使用 Nestjs 向需要授权(客户端密钥和秘密)的第三方 API 发送 Post 请求。有人知道如何在请求中附加标头吗?我想使用axio的HttpService。

小智 5

为 post 请求提供HttpService自定义 headers 对象

this.httpService.post('http://www.stackoverflow.com', { my: 'data' }, { headers: { 'x-custom-header': "this a header" }})
Run Code Online (Sandbox Code Playgroud)

将产生一个带有有效负载和自定义标头POST的请求{ my: 'data' }x-custom-header: this is header

嵌套下面HttpService有一个实例,因此您可以在axios 文档axios中找到更多信息