简体   繁体   English

我收到错误消息“ org.springframework.web.client.HttpClientErrorException $ BadRequest:400错误请求”

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

I'm getting this error "org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request" while trying to internally call POST API from another GET API in spring boot. 尝试在春季启动时从另一个GET API内部调用POST API时,出现此错误“ org.springframework.web.client.HttpClientErrorException $ BadRequest:400错误的请求”。 following is the code. 以下是代码。 also I'm getting multipart file as input in the get api and wants to send that file to this internal post api 我也正在获取多部分文件作为get api中的输入,并想将该文件发送到此内部post api

Path tempFile = Files.createTempFile(null, null); 路径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.

相关问题 我收到错误 org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request - I am getting the Error org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request org.springframework.web.client.HttpClientErrorException$BadRequest: 400 错误请求 - org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request binance - org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request binance org.springframework.web.client.HttpClientErrorException:400错误的请求 - org.springframework.web.client.HttpClientErrorException: 400 Bad Request org.springframework.web.client.HttpClientErrorException: 400 错误的 PUT 请求 - org.springframework.web.client.HttpClientErrorException: 400 Bad Request for PUT org.springframework.web.client.HttpClientErrorException:RestTemplate 中的 400 错误请求 - org.springframework.web.client.HttpClientErrorException: 400 Bad Request in RestTemplate RestTemplate.postForObject - 错误:org.springframework.web.client.HttpClientErrorException:400错误请求 - RestTemplate.postForObject - Error: org.springframework.web.client.HttpClientErrorException: 400 Bad Request org.springframework.web.client.HttpClientErrorException:400使用HttpEntity restTemplate.exchange的错误请求 - org.springframework.web.client.HttpClientErrorException: 400 Bad Request using HttpEntity restTemplate.exchange org.springframework.web.client.HttpClientErrorException 400 RestTemplate.postForEntity - org.springframework.web.client.HttpClientErrorException 400 RestTemplate.postForEntity org.springframework.web.client.HttpClientErrorException:400空 - org.springframework.web.client.HttpClientErrorException: 400 null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM