繁体   English   中英

REST API,不能在我的URL中输入“%20”或“ +”作为空格。 网址未提取

[英]REST API, can't put “%20” or “+” in my URL for spaces. The URL isn't being fetched

我从控制台收到错误消息org.springframework.web.client.HttpClientErrorException:400 null ,这意味着我的URL发送了服务器无法理解的错误请求。

但是,每当我输入没有%20+号的网址时,

示例: 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;
}

尝试使用URLEncoder.encode()对URL进行编码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM