作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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/
我是一名优秀的程序员,十分优秀!