0

When converting http servlet request object to string, I am always getting a "" string. This is my code.

private fun getBody(request: HttpServletRequest): String {
    var inputAsString = ""
    try {
        var inputStream: InputStream  = request.inputStream
        if (inputStream != null) {
            inputAsString = inputStream.bufferedReader().use { it.readText() }
        }
    } catch (ex: IOException) {
        throw ex
    }
    return inputAsString
}
1
  • I am using application/json as content-type Commented Mar 14, 2018 at 17:51

1 Answer 1

1

1) Your code might look better if you rewrite it like this:

private fun getBody(request: HttpServletRequest): String = request
    .inputStream.bufferedReader().use { it.readText() }

2) Your problem is not in this code, because it works!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.