跟随一个说我需要发送此POST请求的API:
POST https://api.vasttrafik.se/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: Basic UmJseEkyeTFsWVNFTTZ0Z2J6anBTa2E0R1o6Wk1nSkR0Y0pddaRGV4OTJldUxpQUdYOFExUnU=
grant_type=client_credentials&scope=<device_id>
我正在尝试在春季启动时构建相应的POST-req,这就是我想出的。但是我最终遇到标题中描述的错误。
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type:", "application/x-www-form-urlencoded");
headers.set("Authorization", "Basic UmJseEkyeTFsWVNFTTZ0Z2J6anBTa2E0R1o6Wk1nSkR0Y0paRGV4OTJldUxpQUdYOFExUnU=");
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
ResponseEntity<String> respEntity = restTemplate.exchange("https://api.vasttrafik.se/token", HttpMethod.POST, entity, String.class);
System.out.println(respEntity);