【问题标题】:java.io.IOException: WebSocket method must be a GETjava.io.IOException:WebSocket 方法必须是 GET
【发布时间】:2017-10-27 03:21:33
【问题描述】:

我正在尝试编写一个 websocket 客户端应用程序,我必须在其中订阅一个 websocket URL,我正在使用 play-ws 来做同样的事情。但得到如下异常。

线程“main”java.io.IOException 中的异常:WebSocket 方法必须 成为一个 GET

使用的依赖:

"com.typesafe.play" %% "play-ws" % "2.4.0-M1"

下面是我用来获取websocket客户端的一段代码,

trait PlayHelper {
  val config = new NingAsyncHttpClientConfigBuilder(DefaultWSClientConfig()).build()
  val builder = new AsyncHttpClientConfig.Builder(config)
  val wsClient = new NingWSClient(builder.build())

  def getBody(future: Future[WSResponse]) = {
    val response = Await.result(future, Duration.Inf);
    if (response.status != 200)
      throw new Exception(response.statusText);
    response.body
  }
}

object Client extends PlayHelper with App{

  def subscribe()={
    val url = "ws://localhost:8080"
    val body = getBody(wsClient.url(url).get())
    Thread.sleep(1000)
    println(s"body: $body")
  }
  subscribe()
}

异常屏幕截图如下:

寻求此问题的帮助。

【问题讨论】:

    标签: scala playframework websocket client typesafe


    【解决方案1】:

    我不认为play-ws 支持websockets,你可能想直接使用AsyncHttpClienthttps://github.com/AsyncHttpClient/async-http-client#websocket

    【讨论】:

    • 我自己没有,上次用akka-http作为ws服务器连接
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多