繁体   English   中英

Java Akka 演员的 HTTP POST 请求未命中发布路径

[英]Java Akka actor's HTTP POST request not hitting the post path

我正在使用 akka 版本 2.6.17 和 akka http 10.2.7 创建一个发布请求。 我的系统绑定到端口 8080,可以很好地接收来自 Postman 的 post 请求。 然而,当从 akka 自身内部发送一个 post 请求(一个发送 post 请求的 actor)时,POST 路径永远不会被命中。 这是post请求

public void postStockCheck(){
        String data = "{\"id\": \"yes\"}";
        HttpRequest.POST("http://localhost:8080/hello")
        .withEntity(HttpEntities.create(ContentTypes.TEXT_PLAIN_UTF8, data));
    }

这是路径:

return route(
        path("hello", () ->
            post(() ->
                entity(Unmarshaller.entityToString(), (string) -> {
                  System.out.println("request body: " + string);
                  return complete("Success");
                })
              )));
      }

如前所述,路径将从邮递员那里工作。 如果我遗漏了什么,任何帮助表示赞赏!

postStockCheck您创建了一个HttpRequest ,但尚未触发它。 要触发请求,您可以使用Http singleRequest方法。

public void postStockCheck(ActorSystem system) {
    String data = "{\"id\": \"yes\"}";

    Http.get(system)
            .singleRequest(HttpRequest.POST("http://localhost:8080/hello")
            .withEntity(HttpEntities.create(ContentTypes.TEXT_PLAIN_UTF8, data)));
}

要更好地了解触发请求和收集响应,请阅读文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM