【问题标题】:Send body with get method in angular HttpClient. PostMan send body method get在 Angular HttpClient 中使用 get 方法发送正文。 PostMan 发送正文方法获取
【发布时间】:2020-04-21 04:10:52
【问题描述】:

在使用 get 发送端点时,我添加了它返回值的主体,但是如果我使用 httpcliente 使用 angular 执行此操作,这不会向我显示使用 spring boot 消耗后端的主体

consuming with postman

Cosuming with postman and httpCliente

Backend - springboot

header = new HttpHeaders().set('Authorization', this.auth.isToken())
    .set('Content-Type', 'application/json')
    .set('Accept-Language', 'UTF-8')
    .set('Cache-Control', 'no-cache');

const url = 'api/servicios/servicios-impuestos-clientes';

const object = JSON.stringify(body);

const options = {
    headers: this.header,
    body: JSON.stringify({ 'impuestos' [1, 2] }),
    // tslint:disable-next-line: quotemark
    // tslint:disable-next-line: object-literal-shorthand
    params: new HttpParams().append('cliente', 1 + '')
};

console.log(options);
return this.http.get<Servicios>(url, options).pipe(map(result => {
    return result;
})); 

【问题讨论】:

标签: angular typescript spring-boot httpclient angular9


【解决方案1】:

通常 GET 没有正文。这就是大多数 HTTP 客户端不允许这样做的原因。

但这是可能的。

查看这个问题:HTTP GET with request body

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-29
    • 2019-08-29
    • 1970-01-01
    • 2021-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多