带主体的Angular HttpClient Get方法 [英] Angular HttpClient Get method with body

查看:56
本文介绍了带主体的Angular HttpClient Get方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在改进现有的API,并且要求提供一种可以接受多个搜索条件并根据这些条件执行查询的单一get方法.

I'm improving an existing API, and the requirement is to provide a single get method which can accept multiple search criteria and based on those criteria perform the query.

我正在使用Spring MVC. get方法签名:

I'm using Spring MVC. The get method signature:

@GetMapping("/subscribers")
public ResponseEntity<List<SubscriberDTO>> getAllSubscribers(Pageable pageable, @RequestBody List<SearchCriteria> lstSearchCriteria)

该实现按预期在邮递员上进行了测试

The implementation is working as expected tested on Postman

现在我要去Angular实现前端,但是我找不到通过HttpClient Get方法发送正文的方法...

Now I was going to Angular to implementing the front end and I can't find a way to send a body through HttpClient Get method...

我有点卡住了.我应该在标题上发送搜索条件吗?还是有更好的方法呢?

I'm kind of stuck. Should I send the search criteria over headers? Or there's a better way of doing it?

推荐答案

据我所知,您不能使用HttpClient get发送正文.您至少可以使用该查询来使它成为惯用语言. (或者,您可以尝试以某种方式强行解决此问题).

As far as I can tell you cannot use HttpClient get to send a body. You could use the query at least for it to be idiomatic. (Or you can try to force the issue somehow).

让我们说您有一个符合条件的数组:

Lets say you have an array with your criteria:

const criteria = [ {a: 25}, {b: 23} ];
http.get(url + '/?criteria='+ encodeURIComponent( JSON.stringify(criteria)));

在GET请求中发送正文违反了某些RFC标准,即使可行,您也必须召唤一些神秘的恶魔.

Sending a body in a GET request is a violation of some RFC standard, and even though it might work you're bound to summon some arcane demons.

这篇关于带主体的Angular HttpClient Get方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆