HttpClient抛出403

时间:2011-08-09 06:16:34

标签: java apache httpclient

尝试使用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();

1 个答案:

答案 0 :(得分:0)

我认为这与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,并尝试在浏览器创建时复制请求。

另外,尝试捕捉exceptino

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