Android studio无法解析符号'HttpClient'

img*_*one 3 java android android-studio

我有一个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);
    }

}
Run Code Online (Sandbox Code Playgroud)

但我找不到HttpClient库.

我将从Apache下载的.jar文件(http://hc.apache.org/downloads.cgi)添加到dir/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'
Run Code Online (Sandbox Code Playgroud)

}

但仍然无法工作..

我该怎么办?

Rus*_*oid 6

在build.gradle中添加它(模块:app)

android {
    useLibrary 'org.apache.http.legacy'
}
Run Code Online (Sandbox Code Playgroud)

它的工作