Why is HttpServletRequest inputstream empty?

后端 未结 7 1674
春和景丽
春和景丽 2020-11-30 05:52

I have this code where I read the input from a request input stream and use a JacksonMapper to convert into a POJO. Its running in a jetty 7 container with guice support.

7条回答
  •  醉话见心
    2020-11-30 06:22

    I had the problem that my request InputStream was always empty with Jetty 6.1.15, and found out that it was caused by a missing or wrong "Content-Type" header.

    I generate the requests in another Java program with HttpUrlConnection. When I did not set the Content-Type header explicitly, the InputStream returned by request.getInputStream() in the receiving program was always empty. When I set the content type to "binary/octet-stream", the InputStream of the request contained the correct data.

    The only method that is called on the request object before getInputStream() is getContentLength().

提交回复
热议问题