@Override public void handle(HttpRequest request, HttpResponse response, HttpContext httpContext) throws HttpException, IOException { // Check first if (!(request instanceof HttpEntityEnclosingRequest)) { // Handle error return; } // Now we can get the entity HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity(); if (entity == null) { // Handle error return; } // Now we have the entity (ie body of the request) we can use it Header type = entity.getContentType(); // Well, you could get this from headers final String strContentType = type.getValue(); // We can read the content from the InputStream InputStream is = entity.getContent(); // Or byte[] content = EntityUtils.toByteArray(entity); String = EntityUtils.toString(entity); // Sadly, EntityUtils has nothing for multipart/form-data }
Programming Tips - Apache HttpCore Server: get the body of a request
Date: 2020jun25
Language: Java
Q. Apache HttpCore Server: get the body of a request
A. The HttpRequest is actually an HttpEntityEnclosingRequest which has the body