java.lang.NoSuchFieldError:org.apache.http.message.BasicHeaderValueFormatter.INSTANCE错误

时间:2015-11-04 19:57:53

标签: android http

我的错误:

java.lang.NoSuchFieldError:org.apache.http.message.BasicHeaderValueFormatter.INSTANCE

在这一行:

HttpResponse response = httpClient.execute(request);

方法发布获取fileName格式为: /storage/primary/legacy/Pictures/JPEG_20151104_214940_2023234301.jpg

我的代码:

public static String POST(String path, JSONObject params, String fileName)
            throws ClientProtocolException, IOException {
        HttpPost request = new HttpPost(url + path);

        MultipartEntity multipartEntity = new MultipartEntity();

        FileBody bin = new FileBody(new File(fileName), "image/jpeg");
        multipartEntity.addPart("photo", bin);
        for (Object obj : params.entrySet()) {
            Entry e = (Entry)obj;
            multipartEntity.addPart((String)e.getKey(), new StringBody((String)e.getValue()));
        }
        request.setEntity(multipartEntity);
        HttpResponse response = httpClient.execute(request);

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String result = "";
        String line = "";
        while ((line = bufferedReader.readLine()) != null)
            result += line;
        bufferedReader.close();
        return result;
    }

我的傻瓜:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "ua.romanpotapskiy.antihawk.prokaton"
        minSdkVersion 10
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.andreabaccega:android-form-edittext:1.2.1@aar'
    compile files('libs/gson-2.2.1.jar')
    compile files('libs/json-simple-1.1.1.jar')
    compile files('libs/httpmime-4.5.1.jar')
    compile files('libs/httpcore-4.4.3.jar')
    compile files('libs/httpclient-4.5.1.jar')
}

我想使用HTTP POST将文件(特定于图像)上传到服务器。如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我解决了我的问题,我删除了所有的库并下载新闻:

  • httpmime-4.3.1
  • 的HttpCore-4.3
  • 谷歌-HTTP-客户1.10.3-β
  • 谷歌OAuth的客户端 - java6-1.13.1-β
  • 谷歌OAuth的客户端应用服务引擎-1.10.1-β-来源
  • 谷歌-HTTP-客户android3-1.10.1-β-来源
  • Apache的mime4j核-0.7.2来源