0

I have an issue while using multipart to upload post data to server.

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Connection", "Keep-Alive");
conn.addRequestProperty("Content-length", reqEntity.getContentLength() +"");
conn.addRequestProperty(reqEntity.getContentType().getName(),reqEntity.getContentType().getValue());

This thing works fine when I use the following in the build.gradel

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.2"
    //useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.valuelabs.fup"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

when the target version is changed to 23 and compileSdkVersion is changed to 23 which is the latest,

conn.addRequestProperty(reqEntity.getContentType().getName(),reqEntity.getContentType().getValue());

This line is throwing error saying getName and getValue methods are not found,

How should i solve this issue, what are the alternate methods to these methods. Any help is greatly appreciated. Thanks in advance.

Selvin
  • 6,598
  • 3
  • 37
  • 43
  • asked bazillion times: apache http client library was removed from framework – Selvin Mar 04 '16 at 05:15
  • yes but what is the solution? simply down voting the question doesn't answer the question. I have tried many things like useLibrary 'org.apache.http.legacy', but still it doesn't help me. – Programming Pirate Mar 04 '16 at 05:19
  • 1
    `useLibrary 'org.apache.http.legacy'` where did you put this? – Selvin Mar 04 '16 at 05:21
  • android { compileSdkVersion 22 buildToolsVersion "23.0.2" useLibrary 'org.apache.http.legacy' defaultConfig { applicationId "com.valuelabs.fup" minSdkVersion 15 targetSdkVersion 22 versionCode 1 versionName "1.0" } – Programming Pirate Mar 04 '16 at 05:22
  • which com.android.tools.build version ? which version of apache mime? – Selvin Mar 04 '16 at 05:22
  • android { compileSdkVersion 23 buildToolsVersion "23.0.2" useLibrary 'org.apache.http.legacy' defaultConfig { applicationId "com.valuelabs.fup" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } – Programming Pirate Mar 04 '16 at 05:23
  • this was the unedited code that caused problem – Programming Pirate Mar 04 '16 at 05:23
  • @Selvin i added compile('org.apache.httpcomponents:httpmime:4.3.6') { exclude module: 'httpclient' } compile 'org.apache.httpcomponents:httpclient-android:4.3.5' – Programming Pirate Mar 04 '16 at 05:24
  • Hi @Selvin I have tried with classpath 'com.android.tools.build:gradle:1.5.0' and classpath 'com.android.tools.build:gradle:1.3.0' but here it says the MultipartEntity is depricated and can't access it – Programming Pirate Mar 04 '16 at 05:37
  • I have solved it using org.apache.http.entity.mime.MultipartEntityBuilder; – Programming Pirate Mar 04 '16 at 06:09
  • For your sanity it would be better choose different http client library ... I was using apache for long time but now I'm choosing okhttp – Selvin Mar 04 '16 at 07:38
  • Thank you @Selvin will consider your advice – Programming Pirate Mar 04 '16 at 09:01

0 Answers0