Вопрос

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?

Это было полезно?

Решение

Path in POST command was missing leading slash, simply.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top