gpt4 book ai didi

java - 如何连接 Android 4.3.5 (GA) 的 apache HttpClient 库?

转载 作者:行者123 更新时间:2023-12-01 10:02:34 26 4
gpt4 key购买 nike

我需要将 zip 目录发送到服务器端

据我所知我必须使用

CloseableHttpClient httpClient = HttpClients.createDefault();

HttpPost uploadFile = new HttpPost("...");

MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("file", new File("..."), ContentType.APPLICATION_OCTET_STREAM, "file.ext");
HttpEntity multipart = builder.build();

uploadFile.setEntity(multipart);

CloseableHttpResponse response = httpClient.execute(uploadFile);
HttpEntity responseEntity = response.getEntity();

为此,我需要连接库 apache HttpClient for Android 4.3.5 (GA)我在谷歌上搜索并喜欢一些如何连接的示例,根据这些示例我需要在我的构建文件中添加一些行

dependencies {
compile files('libs/mapquest-android-sdk-1.0.1.jar')
compile files('libs/osmdroid-android-3.0.8.jar')
compile files('libs/slf4j-android-1.5.8.jar')
compile 'org.apache.httpcomponents:httpclient:4.3.5'
}

我已经做到了,但是当我尝试在我的类中添加导入时仍然存在问题

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

stydio 没有看到这一点。

最佳答案

最终我添加了

compile 'org.apache.directory.studio:org.apache.commons.io:2.4' to the build.gradle file

android {
useLibrary 'org.apache.http.legacy'
}

关于java - 如何连接 Android 4.3.5 (GA) 的 apache HttpClient 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36689840/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com