使用restTemplate.exchange()出现错误404,但该网址适用于Postman

时间:2018-12-07 13:41:23

标签: java spring

HttpHeaders headers = new HttpHeaders();
headers.put("key", new ArrayList<String>(Arrays.asList("some key")));
headers.put("token", new ArrayList<String>(Arrays.asList("some token")));

HttpEntity httpEntity = new HttpEntity(headers); 

ResponseEntity<String> response = restTemplate.exchange(new URI(myUrl), HttpMethod.GET, httpEntity, String.class);

当我将Google的页面作为myUrl提供时,它运行良好。但是,当我提供特定的URL(在邮递员或浏览器上正常工作)时,它将失败。

Caused by: org.springframework.web.client.HttpClientErrorException: 404 NOT FOUND

知道我在做什么错吗?

谢谢

0 个答案:

没有答案