我的设备有 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?我该如何调试呢?