[英]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.