Utilizzando l'esempio di classe ElementalHttpServer trovato qui:Apache HttpCore, semplice server per riprendere dati post ricevuti
Sono in grado di ricevere correttamente dati post, il mio obiettivo è quello di convertire i dati post ricevuti in un stringa che posso stampare. Ho modificato HttpFileHandler come segue, usando eneity.getContent() per ottenere inputStream, ma non sono sicuro di come posso convertire inputStream in una stringa.
static class HttpFileHandler implements HttpRequestHandler {
private final String docRoot;
public HttpFileHandler(final String docRoot) {
super();
this.docRoot = docRoot;
}
public void handle(
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
throw new MethodNotSupportedException(method + " method not supported");
}
String target = request.getRequestLine().getUri();
if (request instanceof HttpEntityEnclosingRequest) {
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
byte[] entityContent = EntityUtils.toByteArray(entity);
InputStream inputStream = entity.getContent();
String str= inputStream.toString();
byte[] b3=str.getBytes();
String st = new String(b3);
System.out.println(st);
for(int i=0;i<b3.length;i++) {
System.out.print(b3[i]+"\t");
}
System.out.println("Incoming entity content (bytes): " + entityContent.length);
}
}
}
Grazie per tutte le idee
che funziona perfettamente, grazie mille !! – Hoofamon
Prego :) –