2020-03-14

RestTemplate提交表单

RestTemplate client = new RestTemplate();
HttpHeaders headers = new HttpHeaders();//  请勿轻易改变此提交方式,大部分的情况下,提交方式都是表单提交headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);Untitled//  封装参数,千万不要替换为Map与HashMap,否则参数无法传递MultiValueMap params= new LinkedMultiValueMap();//  也支持中文params.add("username", "用户名");params.add("password", "123456");HttpEntity> requestEntity = new HttpEntity>(params, headers);//  执行HTTP请求ResponseEntity response = client.exchange(url, HttpMethod.POST, requestEntity, String.class);

你可能感兴趣的:(笔记)