写项目的时候看了一下需要发送一个带json的请求体去一个api,因为用了spring的框架,就想要用框架下的请求方法,看了一下spring有一个RestTemplate的方法可以来做个事情,就尝试写了以下代码
post请求
public String returnfundname() {
String url = "https://api.doctorxiong.club/v1/fund/rank";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
MediaType type=MediaType.parseMediaType("application/json;charset=UTF-8");
headers.setContentType(type);
// MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); -- 有博客中写道如果没有header要使用multiValuemap,有headers就要使用hashmap,尚未验证。
HashMap<String, String>map = new HashMap<>();
map.put("sort",