带主体的Angular HttpClient Get方法

编程入门 行业动态 更新时间:2024-10-24 11:24:29
本文介绍了带主体的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方法

本文发布于:2023-10-31 07:44:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545473.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主体   方法   Angular   HttpClient

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!