【问题标题】:How to add org.apache.http.legacy into sbt如何将 org.apache.http.legacy 添加到 sbt
【发布时间】:2016-12-17 02:54:13
【问题描述】:

我正在使用 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();
    }
}

【问题讨论】:

    标签: java sbt apache-commons-httpclient


    【解决方案1】:

    在 google 上快速搜索将我带到 org.apache.http.legacy

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

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

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

    【讨论】:

      猜你喜欢
      • 2017-07-04
      • 2016-02-07
      • 2017-09-19
      • 2013-12-11
      • 1970-01-01
      • 2011-09-27
      • 2016-11-04
      • 2018-05-03
      • 2013-10-26
      相关资源
      最近更新 更多