【问题标题】:Httppost cannot find method setConfig androidHttppost找不到方法setConfig android
【发布时间】:2018-03-06 13:34:23
【问题描述】:

我正在尝试使用httpclient-4.5.5 编写HttpPost 请求。 我在httpPost.setConfig(requestConfig); 行中收到error

        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(mEntityBuilder.build());

        RequestConfig requestConfig = RequestConfig.custom()
                .setConnectionRequestTimeout(timeout)
                .setConnectTimeout(timeout).setSocketTimeout(timeout)
                .build();
        httpPost.setConfig(requestConfig);

        HttpResponse response = httpClient.execute(httpPost);

错误是 - Error:(97, 21) error: cannot find symbol method setConfig(RequestConfig)

我查看了 HttpPost 类,它扩展了 HttpEntityEnclosureRequestBase,后者又扩展了具有公共方法 setConfig 的 HttpRequestBase。

请帮帮我。

【问题讨论】:

  • 我在 app gradle 文件中添加了 android {useLibrary 'org.apache.http.legacy'} 行。我已将 httpclient-4.5.5 jar 模块添加到我的 android 项目中。

标签: android apache httpclient apache-httpclient-4.x


【解决方案1】:

删除 gradle 文件中的{useLibrary 'org.apache.http.legacy'} 如果您在 gradle 文件中添加 {useLibrary 'org.apache.http.legacy'}。 Android Studio 将在 Android SDK 中使用"org.apache.http.client.methods.HttpPost"。但它没有关于 setConfig() 的方法。在您的项目中添加"httpclient.jar"

【讨论】:

    猜你喜欢
    • 2012-08-15
    • 2013-07-24
    • 2020-03-12
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多