我正在使用Play Framework我正在尝试使用内置的 WS
支持发出 HTTP 请求。每当我尝试在 Controller 中发出此 HTTP 请求时,我都会收到此错误
error: cannot find symbol
代码
public static Result foo(){
return async(//ERROR ON THIS LINE FOR `async()`
WS.url(GoogleStrategy.getTokenUrl).post(getTokenUrlParams).map(
new F.Function<WSResponse, Object>() {
@Override
public Object apply(WSResponse wsResponse) throws Throwable {
return ok(wsResponse.asJson());
}
}
)
);
}
这很奇怪,因为在文档中显示的所有示例中,这似乎是执行我想做的事情的正确方法。
最佳答案
您几乎肯定正在查看旧版本的文档。不再需要async()
。
当前版本:https://www.playframework.com/documentation/2.3.x/JavaAsync
public static Promise<Result> foo(){
return WS.url(GoogleStrategy.getTokenUrl).post(getTokenUrlParams).map(
new F.Function<WSResponse, Result>() {
@Override
public Object apply(WSResponse wsResponse) throws Throwable {
return ok(wsResponse.asJson());
}
}
);
}
关于java - Play Framework : Cannot find symbol "async",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26267689/