【问题标题】:Which httpmime version can I use with Android's HttpClient?我可以在 Android 的 HttpClient 中使用哪个 httpmime 版本?
【发布时间】:2014-09-05 20:01:18
【问题描述】:

我需要使用 Android 的 HttpClient 上传文件。不幸的是,Android doesn't include MultipartEntity,所以我必须使用Apache's httpmime library

我不想在 Android 的 HttpClient 和官方的 HttpClient 之间引起可能的冲突。另外,我不想引入比我必须的更多的外部库,因为我需要保持我的方法数量很少。

什么版本的 httpmime 可以与 Android 的 HttpClient 一起使用? All of the questions我看过recommending httpmime也推荐using Apache's official HttpClient or HttpCore

(我知道我应该使用Retrofit,但我必须使用Android的HttpClient才能与其他库兼容。)

【问题讨论】:

    标签: android file-upload androidhttpclient


    【解决方案1】:
    dependencies {
        compile group: 'org.apache.httpcomponents', name: 'httpclient-android', version: '4.3.5'
        compile 'org.apache.httpcomponents:httpmime:4.3.5'
    }
    

    【讨论】:

    • 虽然compile 'org.apache.httpcomponents:httpclient-android:4.3.5'可能看起来更好。
    【解决方案2】:

    httpmime-4.2.6.jar 自己运行良好。除了那个 jar,我不需要其他依赖项。

    如果您使用像 Mavengradle 这样的依赖管理构建系统,您会注意到 httpmime-4.2.6 depends on httpcore-4.2.5。 Android 的 HttpClient 似乎与httpcore-4.2.5 兼容,所以我只是排除了该依赖项。我的实际依赖声明如下:

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.2.6</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpcore</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    

    【讨论】:

    • 非常感谢这个解决方案!
    猜你喜欢
    • 2016-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    • 1970-01-01
    • 1970-01-01
    • 2019-02-07
    • 1970-01-01
    相关资源
    最近更新 更多