HttpClient 抛出 403

发布于 2024-11-28 17:48:46 字数 398 浏览 2 评论 0原文

尝试使用 apache HttpClient 访问 http://forum.worldoftanks.eu/index.php?app=members 但一直收到 403。有人可以帮忙吗? 一直在摆弄这件作品作为起点:

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpRequestBase method = new HttpGet(theUrl);
String s = httpClient.execute(method, new BasicResponseHandler());    
System.out.println(s);
httpClient.getConnectionManager().shutdown();

trying to access http://forum.worldoftanks.eu/index.php?app=members using apache HttpClient but keep getting 403. Can anyone help out?
Been fiddling with this piece as a starting point:

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpRequestBase method = new HttpGet(theUrl);
String s = httpClient.execute(method, new BasicResponseHandler());    
System.out.println(s);
httpClient.getConnectionManager().shutdown();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青丝拂面 2024-12-05 17:48:46

我认为这与 HttpClient 无关。我尝试过这个

$ wget http://forum.worldoftanks.eu/index.php?app=members
--2011-08-08 23:17:52--  http://forum.worldoftanks.eu/index.php?app=members
Resolving forum.worldoftanks.eu (forum.worldoftanks.eu)... 213.252.177.21, 213.2
52.177.20
Connecting to forum.worldoftanks.eu (forum.worldoftanks.eu)|213.252.177.21|:80..
. connected.
HTTP request sent, awaiting response... 403 Forbidden
2011-08-08 23:17:56 ERROR 403: Forbidden.

但没有运气。

但我可以在浏览器中点击它。当未发送适当的浏览器标头时,可能有一些服务器逻辑返回 403。我的下一步是使用 FireBug 并尝试在浏览器发出请求时复制该请求。

另外,尝试捕获异常

  } catch (HttpResponseException e) {
    System.err.println(e.response.parseAsString());
  }

I don't think this is related to HttpClient. I tried this

$ wget http://forum.worldoftanks.eu/index.php?app=members
--2011-08-08 23:17:52--  http://forum.worldoftanks.eu/index.php?app=members
Resolving forum.worldoftanks.eu (forum.worldoftanks.eu)... 213.252.177.21, 213.2
52.177.20
Connecting to forum.worldoftanks.eu (forum.worldoftanks.eu)|213.252.177.21|:80..
. connected.
HTTP request sent, awaiting response... 403 Forbidden
2011-08-08 23:17:56 ERROR 403: Forbidden.

with no luck.

Yet I can hit it in the browser. It might be that there is some server logic returning 403s when an appropriate browser headers aren't sent. My next step would be to use FireBug and try to replicate the request as your browser makes it.

Also, try catching the exceptino

  } catch (HttpResponseException e) {
    System.err.println(e.response.parseAsString());
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文