简体   繁体   中英

Tomcat returns 400 without running a servlet

My device has UBlox (hardware component) to send POST HTTP/1.0 requests.

Headers that I receiving in Tomcat are following:

POST sc2-http-connector-3.0.0/report HTTP/1.0
Content-Type: application/octet-stream
Host: xx.xx.xx.xx:8080
Connection: TE, close
TE: trailers
Content-Length: 152

Request body is actually binary data. Tomcat just returns 400 to the client and not even running servlet which just prints header, body, and so on.

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    System.out.println("getMethod :: " + request.getMethod());
    System.out.println("getContentLength :: " + request.getContentLength());
    System.out.println("getContentType :: " + request.getContentType());
    System.out.println("getProtocol :: " + request.getProtocol());
    System.out.println("getRemoteAddr :: " + request.getRemoteAddr());
    System.out.println("getRemoteHost :: " + request.getRemoteHost());
    System.out.println("getRemotePort :: " + request.getRemotePort());
    System.out.println("getRemoteUser :: " + request.getRemoteUser());

    printHeaders(request);

    printByteStream(request.getInputStream());

    System.out.println("------------- parts, if any -------------");
    for (Part part : request.getParts()) {
        System.out.println("size :: " + part.getSize());
        System.out.println("contentType :: " + part.getContentType());
        System.out.println("name :: " + part.getName());
        printHeaders(part);
        printByteStream(part.getInputStream());
    }

    response.setStatus(HttpServletResponse.SC_OK);
}

Doesn't seem to be a problem with headers. I think it should be something wrong with the data. But still, why Tomcat returns 400 and do not pass control to my servlet? How can I debug this?

简而言之,POST命令中的路径缺少前导斜线。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM