gpt4 book ai didi

java - 如何将 org.apache.http.legacy 添加到 sbt 中

转载 作者:行者123 更新时间:2023-12-02 03:26:00 25 4
gpt4 key购买 nike

我正在使用 apache httpclient,但找不到

import org.apache.http.impl.client.HttpClients;

在 Google 上快速搜索,找到了 org.apache.http.legacy,但我找不到 org.apache.http.legacy 的组、工件和修订版

它们是什么以及如何将该依赖项添加到我的 build.sbt 文件中?总堆栈跟踪为

[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:13: cannot find symbol
[error] symbol: class HttpClients
[error] location: package org.apache.http.impl.client
[error] import org.apache.http.impl.client.HttpClients;
[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:66: cannot find symbol
[error] symbol: variable HttpClients
[error] location: class utils.LocalUtils
[error] HttpClient httpclient = HttpClients.createDefault();
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java uses or overrides a deprecated API.
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: Recompile with -Xlint:deprecation for details.
[error] (compile:compileIncremental) javac returned nonzero exit code
[info] Compiling 6 Scala sources and 18 Java sources to /Users/vangapellisanthosh/Development/coupon-engine-play/target/scala-2.11/classes...
[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:13: cannot find symbol
[error] symbol: class HttpClients
[error] location: package org.apache.http.impl.client
[error] import org.apache.http.impl.client.HttpClients;
[error] /Users/vangapellisanthosh/Development/coupon-engine-play/app/utils/LocalUtils.java:66: cannot find symbol
[error] symbol: variable HttpClients
[error] location: class utils.LocalUtils
[error] HttpClient httpclient = HttpClients.createDefault();
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java uses or overrides a deprecated API.
[info] /Users/vangapellisanthosh/Development/coupon-engine-play/app/controllers/CouponsController.java: Recompile with -Xlint:deprecation for details.
[error] (compile:compileIncremental) javac returned nonzero exit code
[error] application -

我的代码是

HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(URL);
httppost.addHeader(API_KEY, X_API_KEY);
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair(GRANT_TYPE, "password"));
params.add(new BasicNameValuePair(USERNAME, _USERNAME));
params.add(new BasicNameValuePair(PASSWORD, O_PASSWORD));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();

if (entity != null) {
InputStream instream = entity.getContent();
try {
System.out.println(instream);
} finally {
instream.close();
}
}

最佳答案

quick search on google lead me to org.apache.http.legacy

不确定您搜索的是什么,但我知道这是 Android 项目常用的依赖项,而不仅仅是任何常规的 SBT 项目

您要查找的内容可以在 MvnRespository 找到

libraryDependencies += "org.apache.httpcomponents" % "httpclient" % "4.5.2"

关于java - 如何将 org.apache.http.legacy 添加到 sbt 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38878205/

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