为什么使用RestTemplate提取数据时总是得到403?

为什么使用RestTemplate提取数据时总是得到403?,第1张

为什么使用RestTemplate提取数据时总是得到403?

尝试将“ User-Agent”标头添加到您的请求中。

将您的代码更改为

try { 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://api.hearthstonejson.com/v1/19776/enUS/cards.json", HttpMethod.GET,entity,Object.class); System.out.println(response);        } catch (Exception ex) {ex.printStackTrace();        }


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5621691.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存