我正在研究vertx.io
网络客户端,我已经被阻止做一个简单的获取... Uff。这是我放在一起的(我在vertx.io
时很新):
private void getUserEmail(String accessToken, Handler<AsyncResult<String>> handler) {
String url = "https://graph.facebook.com/me";
HttpRequest<JsonObject> req = webClient.get(url).as(BodyCodec.jsonObject());
req.addQueryParam("access_token", accessToken);
req.addQueryParam("fields", "name,email");
MultiMap headers = req.headers();
headers.set("Accept", "application/json");
req.send(h -> {
if (h.succeeded()) {
log.info(h.result().toString());
handler.handle(new FutureFactoryImpl().succeededFuture(h.result().bodyAsString()));
} else {
log.error(h.cause());
handler.handle(new FutureFactoryImpl().failedFuture(h.cause()));
}
});
}
我认为它应该是应该的,但事实并非如此。当我发送请求时,我收到此错误:
io.vertx.core.json.DecodeException: Failed to decode: Unrecognized token 'Not': was expecting 'null', 'true', 'false' or NaN
at [Source: Not Found; line: 1, column: 4]
当然如果我通过浏览器做同样的操作,我会得到预期的数据。我阅读了教程并检查了示例,我缺少什么?
答案 0 :(得分:0)
您收到正文的404错误:Not Found
并且编解码器尝试将其解析为JSON并失败。您需要验证您发送的请求是否正确。