从代码获取403响应代码,但从Web浏览器获取200

时间:2019-07-22 07:13:44

标签: java http-proxy

我正在尝试使用我的Java代码访问公共网站https://reqres.in。当我在网络浏览器中致电https://reqres.in/api/users时,浏览器会按预期给出响应。现在,当我尝试使用Java代码执行相同操作时,reqres.in会出现unknowhost异常。我尝试使用以下代码设置代理

System.setProperty("proxySet","true");
System.setProperty("http.proxyHost","xx.xxx.xxx.xx");
System.setProperty("http.proxyPort","yyyy");
System.setProperty("https.proxyHost","xx.xxx.xxx.xx");
System.setProperty("https.proxyPort","yyyy");

放置上述代理后,问题已解决。但是它给了我403代码异常,该代码在浏览器中运行良好。该项目是在intellij中构建的。

0 个答案:

没有答案
相关问题