Can't resolve symbol 'Defaulthttpclient

2019-08-11 05:23发布

问题:

i build a new project.but i have a little problem.i can't use DefaultHttpClient and HttpPost even after i use it in my previous project already.

Is there any external librery i have to add?

i don't know how can i use both of this.

Help me for this issue.

My build.gradle

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 23
        buildToolsVersion "22.0.1"

        defaultConfig {
            applicationId "Id"
            minSdkVersion 14
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }

    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:23.0.1'
        compile files('libs/httpcore-4.3.3.jar')
        compile files('libs/httpmime-4.3.6.jar')
    }

Thanks in advance.........

回答1:

There are two different DefaultHttpClient classes are available in the jars, you imported the wrong one,
Remove the import of DefaultHttpClient from your class file, and add this one,

import org.apache.http.impl.client.DefaultHttpClient;

One more thing, It should not be HttpPost, it will be HttpClient complete example,

import org.apache.http.impl.client.DefaultHttpClient;
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost();