对于Play 2.3.X,非常容易使用WS模块:
WS.url(s"http://$webEndpoint/hand/$handnumber").get()
Run Code Online (Sandbox Code Playgroud)
对于这种简单而直接的用法。
在Play 2.6.x中,根据链接:https : //www.playframework.com/documentation/2.6.x/JavaWS 您需要首先创建一个http客户端。
WSClient customWSClient = play.libs.ws.ahc.AhcWSClient.create(
play.libs.ws.ahc.AhcWSClientConfigFactory.forConfig(
configuration.underlying(),
environment.classLoader()),
null, // no HTTP caching
materializer);
Run Code Online (Sandbox Code Playgroud)
而且,您还需要一个实现器和一个akka系统来支持实现器。
String name = "wsclient";
ActorSystem system = ActorSystem.create(name);
ActorMaterializerSettings settings = ActorMaterializerSettings.create(system);
ActorMaterializer materializer = ActorMaterializer.create(settings, system, name);
// Set up AsyncHttpClient directly from config
AsyncHttpClientConfig asyncHttpClientConfig = new DefaultAsyncHttpClientConfig.Builder()
.setMaxRequestRetry(0)
.setShutdownQuietPeriod(0)
.setShutdownTimeout(0).build();
AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient(asyncHttpClientConfig);
// Set up WSClient instance directly from asynchttpclient.
WSClient client = new AhcWSClient(
asyncHttpClient,
materializer
Run Code Online (Sandbox Code Playgroud)
);
我知道它将为WS客户端添加更多功能,但是当我只想要一个简单的http客户端时,用法变得难以接受,它是如此连接。
当我使用 ssh 登录谷歌云实例时,我遇到了如下问题
$ ssh -i DD2 root@35.237.32.84
Permission denied (publickey).
Run Code Online (Sandbox Code Playgroud)
经过一番测试,我发现错误的原因是公钥签名与google cloud的账号不一致:
例如 :
scuio33@chef-server:~$
Run Code Online (Sandbox Code Playgroud)
在这里,您的帐户是 scuio33,那么您的 pub 文件将是:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBpNeFZyXXXehjPuGCkEjb/t
laNQt0fztORSCFFQIoKHkQzi7SNhp48kagyOHDNj6mY1LmVZB/sIj2oCa1AFupoFuBYc/XILP
rTX60fIlnBYkHl+6Kq/TX2hzKv scuio33
Run Code Online (Sandbox Code Playgroud)
scuio33 将与您的 google 帐户完全相同,否则会出现“权限被拒绝(公钥)”的问题。只有谷歌云有这个限制。
这不是一个“问题”。但是 ssh 到谷歌云失败的提示。