我是Spring的新手,正在尝试使用RestTemplate进行REST请求。Java代码应该与以下curl命令相同:
我对Spring不熟悉,正在尝试使用RestTemplate进行REST请求。Java代码应该与以下curl命令实现相同:
curl --data "name=feature&color=#5843AD" --header "PRIVATE-TOKEN: xyz" "https://someserver.com/api/v3/projects/1/labels"
但是服务器拒绝了RestTemplate,并返回400 Bad Request
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("PRIVATE-TOKEN", "xyz");
HttpEntity<String> entity = new HttpEntity<String>("name=feature&color=#5843AD", headers);
ResponseEntity<LabelCreationResponse> response = restTemplate.exchange("https://someserver.com/api/v3/projects/1/labels", HttpMethod.POST, entity, LabelCreationResponse.class);
有人可以告诉我我做错了什么吗?
CloseableHttpResponse tokenResponse = userWebTokenHTTPclient.execute(httpPost); - veritas