【发布时间】:2016-07-11 03:06:54
【问题描述】:
我想通过这些代码获取“www.google.com”的状态码:
final HttpClient client = new DefaultHttpClient();
final HttpPost method = new HttpPost("http://www.google.com");
try {
HttpResponse response = client.execute(method);
int code = response.getStatusLine().getStatusCode();
Log.i("LOG", "Code : " + code);
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
但它给了我代码“405”意味着我们有问题。 这段代码有什么问题? 给我另一个代码来做同样的工作。但是请一个简单的代码。我是初学者:)
顺便说一句 我听说 httpclient 已被弃用。
【问题讨论】: