0

我正在研究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]

当然,如果我通过浏览器做同样的事情,我会得到预期的数据。我阅读了教程并检查了示例,我错过了什么?

4

1 回答 1

0

您收到正文的 404 错误:Not Found编解码器尝试将其解析为 JSON 并失败。您需要验证您发送的请求是否正确。

于 2017-12-14T10:28:10.390 回答