def sendGetRequest()

in flink-connector-netty/src/main/scala/org/apache/flink/streaming/connectors/netty/example/NettyUtil.scala [121:148]


  def sendGetRequest(url: String): String = {
    val obj: URL = new URL(url)
    val con: HttpURLConnection = obj.openConnection.asInstanceOf[HttpURLConnection]
    con.setRequestMethod("GET")
    val code = try {
      con.getResponseCode
    } catch {
      case e: Throwable => e
    }

    code match {
      case HttpURLConnection.HTTP_OK =>
        val in: BufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream))
        var inputLine: String = ""
        val response: StringBuilder = new StringBuilder
        try {
          while (inputLine != null) {
            response.append(inputLine)
            inputLine = in.readLine()
          }
          in.close()
        } catch {
          case throwable: Exception =>
        }
        response.toString
      case x => throw new Exception("GET request not worked of url: " + url)
    }
  }