簡體   English   中英

我收到錯誤消息“ org.springframework.web.client.HttpClientErrorException $ BadRequest:400錯誤請求”

[英]I'm getting error “org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request”

嘗試在春季啟動時從另一個GET API內部調用POST API時,出現此錯誤“ org.springframework.web.client.HttpClientErrorException $ BadRequest:400錯誤的請求”。 以下是代碼。 我也正在獲取多部分文件作為get api中的輸入,並想將該文件發送到此內部post api

路徑tempFile = Files.createTempFile(null,null);

            Files.write(tempFile, newFile.getBytes());
            File fileToSend = tempFile.toFile();

            FileSystemResource fr = new FileSystemResource(fileToSend);

            String baseUrl = "someURL which is correct";
            URI uri = new URI(baseUrl);
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.MULTIPART_FORM_DATA);
            //headers.set("Content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
            headers.set("Ocp-Apim-Subscription-Key","{key which i dont want to display}");

            MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
            body.add("newFile", fr);

            HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);

            RestTemplate restTemplate = new RestTemplate();
            ResponseEntity<String> response = restTemplate.postForEntity(uri, requestEntity, String.class);

            return response;

在restTemplate.postForEntity方法中傳遞baseUrl字符串而不是uri並嘗試

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM