- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 mashape unirest 的新手,我似乎不知道我做错了什么。
我使用 maven 使用 unirest 作为依赖项,如下所示:
<dependencies>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.3.27</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
接下来,我尝试使用 unirest 通过 java 匿名回调对我的服务器进行异步调用。
import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.lang.*;
import java.io.*;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.async.Callback;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.mashape.unirest.http.options.Options;
public class CRDTClient {
private ArrayList<String> servers;
public AtomicInteger successCount;
public CRDTClient() {
servers = new ArrayList(3);
servers.add("http://localhost:3000");
servers.add("http://localhost:3001");
servers.add("http://localhost:3002");
}
public boolean put(long key, String value) {
final CountDownLatch countDownLatch = new CountDownLatch(servers.size());
successCount = new AtomicInteger();
for (final String serverUrl : servers) {
Future<HttpResponse<JsonNode>> future = Unirest.post(serverUrl + "/cache/{key}/{value}")
.header("accept", "application/json")
.routeParam("key", Long.toString(key))
.routeParam("value", value).asJson()
.asJsonAsync(new Callback<JsonNode>() {
public void failed(UnirestException e) {
System.out.println("The request has failed: " + serverUrl);
countDownLatch.countDown();
}
public void completed(HttpResponse<JsonNode> response) {
int code = response.getStatus();
if (code == 200) {
successCount.incrementAndGet();
}
countDownLatch.countDown();
}
public void cancelled() {
System.out.println("The request has been cancelled");
}
});
}
// Block the thread until all responses gotten
countDownLatch.await();
return (Math.round(successCount.floatValue() / servers.size()) == 1);
}
运行时出现的错误
mvn clean package -e
是
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project client: Compilation failure
[ERROR] /Users/jonguan/Documents/SJSU/cmpe273/cmpe273-lab4/client/src/main/java/edu/sjsu/cmpe/cache/client/CRDTClient.java:[40,20] error: cannot find symbol
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project client: Compilation failure
.../cmpe/cache/client/CRDTClient.java:[40,20] error: cannot find symbol
结果是 .asJsonAsync 上的行
我尝试导入各种类,但似乎不起作用。
最佳答案
我明白了。我真是个傻子。
在上一行,有一个额外的 .asJson
.routeParam("value", value).asJson()
应该是
.routeParam("value", value)
关于java - mashape unirest java Future HttpResponse asJsonAsync 找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27466955/
我正在创建一个执行 POST 操作的 Java 应用程序。我需要执行 HttpRequestWithBody 来发送 JSONObject。我正在使用 Unirest 来完成这项任务。调试时,程序会在
嗨,我是新的 Rest,正在开发 API,其中我从客户端获得的请求参数每次都不同。然后我将不得不调用另一个 API。我想编写一种方法来从 3rd 方 API 获取 JSON 数据。我在网上查了一下,所
我们使用 Unirest 1.5.4 for java。我们的服务器以 204 - NO_CONTENT 状态和空响应正文响应 DELETE 调用。当我执行同步删除调用时,以下调用将以 SocketT
我正在使用 Unirest Java 客户端,如下所示连接到外部 API: public static String loginAsAdmin(String authenticationURL ,
您能否告诉我使用 Unirest 作为 REST 客户端禁用证书验证的方法。 我将 Unirest 与 Java Spring 结合使用。以下是我的源代码: try { HttpRespons
我的网络应用程序似乎内存不足,我认为这是由于线程泄漏。线程似乎一直在等待,并且越来越大,直到内存达到堆大小的顶部。在空闲且不使用 Web 应用程序时,Web 应用程序的本地 Tomcat 服务器上的线
我刚开始接触 API(官方和非官方),我正在使用一个名为 JavaSnap 的 API。 。我一直在搞乱示例代码的非常基本的实现,但遇到了错误。这是非常基本的代码: Snapchat snapchat
我们正在调用后端 2 个 REST 服务(A、B)(GET 方法),这两个服务具有不同的凭据(用户名和密码),但我们遇到了奇怪的行为: 1-如果我们先调用A,身份验证成功,但如果我们调用B,我们将收到
所以我正在使用 java 中的 REST API。我的 POST 请求可以正常工作,但我的代码对我来说似乎有点低效,例如: HttpResponse jsonResponse = Unires
使用 Unirest 时,程序不会退出,直到我们通过调用 Unirest.shutdown() 手动关闭每个线程。如果我只需要提出一个请求,那很简单: private static void asyn
我有一个像这样的类,它使用 Unirest API 进行 HTTP POST 调用 - public class MyClass{ public MyObject getData(){
我正在使用 Unirest 库通过以下代码行调用公开可用的 REST 端点: public void callRest() { String url = "https://upstream.c
制作用于连接 QwintryLogistics API ( http://logistics.qwintry.com ) 的服务,在 Java + Unirest 库上编码,但 API 的所有文档都是
我有一个接收字符串响应的 unirest 请求,但在解析其结果时遇到问题。我做了一项研究,但我看到的只是有关如何解析 json 请求的教程,这显然不是我需要的。不管怎样,请求看起来像这样: publi
我的项目是使用 Spring Boot 框架用 Java 编程语言编写的。我使用 Unirest 库来获取对某些 API 的请求,并且我想以表单形式获取响应,如下所示 List下面我写了一些我尝试提出
我正在尝试通过 PHP 获取从 unirest Node 模块发送的数据。这是我的 Node 代码: unirest.post('http://example.com/api') .h
我正在使用Unirest library用于使用 Python 发出异步 Web 请求。我已阅读文档,但无法找到是否可以使用代理。也许我只是瞎了,有办法将它与 Unirest 一起使用吗? 或者还有其
我尝试使用 Unirest.get(...).asObjectAsync(...) 使用计划任务更新资源。要停止使用 Unirest 的程序,您需要调用 Unirest.shutdown(); 以退出
Unirest 关于代理设置的文档提到要使用: Unirest.setProxy(new HttpHost("127.0.0.1", 8000)); 由于我使用的代理需要身份验证,因此我也需要指定凭据
我想使用 jsonWhois api,但它使用 Unirest 发出服务器请求,看起来它不再维护,无论如何我更愿意使用 curl。 如何将此代码转换为使用 Curl?? $response = Uni
我是一名优秀的程序员,十分优秀!