簡體   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