【发布时间】:2015-06-19 11:19:31
【问题描述】:
我需要同步或异步 HTTP Post/Get 从 Web 服务获取 HTML 数据。我搜索了整个互联网,但我无法给出好的结果。
我尝试使用以下示例:
但没有一个对我有用。
HttpClient 和 HttpGet 被划掉,错误是:
“org.apache.http.client.HttpClient 已弃用”
代码:
try
{
HttpClient client = new DefaultHttpClient();
String getURL = "google.com";
HttpGet get = new HttpGet(getURL);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null)
{
//do something with the response
}
}
catch (Exception e)
{
e.printStackTrace();
}
【问题讨论】:
-
可能是如果您发布您尝试中的错误可能会导致结果。
-
我无法运行应用程序,因为 HttpClient 和 HttpGet 被划掉,错误是:“org.apache.http.client.HttpClient 已弃用” 代码:尝试 { HttpClient client = new DefaultHttpClient();字符串 getURL = "google.com"; HttpGet get = new HttpGet(getURL); HttpResponse responseGet = client.execute(get); HttpEntity resEntityGet = responseGet.getEntity(); if (resEntityGet != null) { //对响应做一些事情 } } catch (Exception e) { e.printStackTrace(); }
-
你需要找出你跑不了的原因
-
编译器告诉我这个错误:“org.apache.http.client.HttpClient is deprecated”