我有一个Android项目,需要使用http请求。
我使用以下简单代码:
public void onGetClick(View v) {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.google.com");
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader
(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
Log.d("WM.ALS", line);
}
}
但是我找不到HttpClient库。
我将从Apache (http://hc.apache.org/downloads.cgi) 下载的.jar文件添加到了/lib目录中,并在 "build.gradle(Module: app)" 文件中添加了以下内容:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.0.1'
compile 'org.apache.httpcomponents:httpcore-4.4.3'
compile 'org.apache.httpcomponents:httpclient-4.5.1'
但是仍然没有效果...
我该怎么办?
HttpURLConnection
? - Dhaval PatelHttpURLConnection
提供相同功能时要使用额外的(已弃用)库? - Dhaval Patel