如何通过 url 中的帖子发送数据(使用 ws (url) .post ())以及如何在同一应用程序中操作该数据
我正在使用ws。以及此代码通过邮件发送消息
public class WebService implements WSBodyReadables, WSBodyWritables {
private final WSClient ws;
@Inject
public WebService(WSClient ws) {
this.ws = ws;
JsonNode json = Json.newObject()
.put("key1", "value1")
.put("key2", "value2");
ws.url("http://localhost:9000/web").post(json);
}
// ...
}
我想在控制器中接收这些数据,我正在使用这段代码:
public class WebServiceController extends Controller{
@Inject WSClient ws;
@Inject
Materializer materializer;
private Server server;
private Content response;
public CompletionStage<Result> web() {
return ws.url("http://localhost:9000/web").get().thenApply(response ->
ok("Feed title: " + response.asJson().findPath("title").asText())
);
}
}
但是访问网址时出现此错误
“CompletionException:java.lang.RuntimeException:从 WS 响应 wsBody 解析 JSON 时出错”
我是 playframework 的新手,我需要做一个网络服务,我可以在其中发布一些信息,然后访问该 url 并捕获该信息。请帮我