HTTP状态500 - 请求处理失败;嵌套的例外是org.springframework.web.client.HttpClientErrorException:403空类型

问题描述 投票:0回答:1

我们正在尝试使用resttemplate春天LIB发送GET或POST请求

看起来像错误Live服务器抛出错误本地环境中工作得非常好

enter image description here

spring spring-mvc
1个回答
1
投票

我想你应该添加一个“用户代理”标头到您的要求。您可以尝试设置自定义的用户代理值或使用一些标识浏览器的价值。

喜欢-

RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36");
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);

Object response = restTemplate.exchange("https://test.prateek.com/tests.json", HttpMethod.GET,entity,Object.class);
© www.soinside.com 2019 - 2024. All rights reserved.