【发布时间】:2018-09-28 15:25:18
【问题描述】:
我从控制台收到错误消息 org.springframework.web.client.HttpClientErrorException: 400 null,这意味着我的 URL 发送了服务器无法理解的错误请求。
但是,每当我输入一个没有 %20 或 + 符号的 URL 时
示例: http://ksr-ca-qmaltjira.ca.kronos.com:8061/rest/api/2/search?jql=project=SUP&maxResults=2 有效,我的数据显示在我的本地页面上。
String username = "confidential";
String password = "confidential";
private static final String jiraBaseURL = "http://ksr-ca-qmaltjira.ca.kronos.com:8061/rest/api/search?jql=project%3D%22Customer%20Support%22%20%26%20type%20%3D%20%22Change%20Request%22%20&maxResults=2";
private RestTemplate restTemplate;
private HttpHeaders httpHeaders;
private HttpHeaders createHeadersWithAuthentication() {
String plainCreds = username + ":" + password;
byte[] base64CredsBytes = Base64.getEncoder().encode(plainCreds.getBytes());
String base64Creds = new String(base64CredsBytes);
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic " + base64Creds);
return headers;
}
@RequestMapping("/cr-follow-up")
public @ResponseBody ResponseEntity<String> getData()
{
restTemplate = new RestTemplate();
httpHeaders = createHeadersWithAuthentication();
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<String>(httpHeaders);
ResponseEntity<String> response = restTemplate.exchange(jiraBaseURL, HttpMethod.GET, entity, String.class);
return response;
}
【问题讨论】:
-
您是否尝试过使用诸如 spring UriComponentsBuilder 之类的 uri 构建器?
-
如果你输入一个空格会发生什么。
-
当你的意思是添加时你做了一个uriencode吗?
-
UriComponentsBuilder我没试过,嗯我试试
-
如果我使用空间它不起作用
标签: java rest spring-boot jira-rest-api