Tomcat在不运行servlet的情况下返回400

时间:2013-04-09 15:11:44

标签: tomcat7 java-7 servlet-3.0 http-1.0

我的设备有UBlox(硬件组件)来发送POST HTTP / 1.0请求。

我在Tomcat中收到的标题如下:

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

请求正文实际上是二进制数据。 Tomcat只返回400到客户端,甚至没有运行只打印标题,正文等的servlet。

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);
}

标题似乎没有问题。我认为数据应该是错误的。但是,为什么Tomcat返回400并且不将控制传递给我的servlet?我该怎么调试呢?

1 个答案:

答案 0 :(得分:0)

POST命令中的路径缺少前导斜杠,只是。