java - read post request values HttpHandler -


I am writing a small Java app that uses an http service that receives the http post command from the client.

I am using this class to apply, package handler and HTTP server in com.sun.net.

I am now implementing a handle (HTTPS exchange exchange) function which handles the request, and I'm stuck in reading the post values ​​received from the request because I have access to these values ​​only HttpExchange .getResponseBody () is the only one output stream.

I'm looking to parse the txt post values ​​and uploaded files.

Please help.

Please help.

> Thanks.

I have written sections that process multipart requests for my project, an HTTP server Uses com.sun.net.httpserver To get photo uploads from a card, the classes that come with Java 6.

This file can help with upload (Multipurpose Post).

For a non-multipurpose post, you will need to do something like this:

  // Define the encoding headers rehearsed = exchange.getrextest headers (); String contentType = reqHeaders.getFirst ("content-type"); String encoding = "ISO-885 9-1"; If (contentType! = Null) {map & lt; String, string & gt; Paramos = value parser Pars (content type); If (Parametantensky ("charset")) {encoding = paramet. ("Charset"); }} // Request Body String Curie Read query string; InputStream = exchange.getRequestBody (); Try {BiteAirOnputStrout Out = New BytereOutStream (); Byte buff [] = new byte [4096]; (Int n = in.read (buf); n & gt; 0; n = in.read (buf)) {out.write (buf, 0, n); } Qry = new string (out.toByteArray (), encoding); } Finally {in.close (); } // parse query map & lt; String, list & lt; String & gt; & Gt; Parameters = new Hashmop & lt; String, list & lt; String & gt; & Gt; (); String defs [] = qry.split ("[& amp;]"); (String diff: dff) {int ix = def.indexOf ('='); String name; string value; If (ix> lt; 0) {name = URLDecoder.decode (def, encoding); Value = ""; } Else {name = URLDecoder.decode (def.substring (0, ix), encoding); Value = URLDecoder.decode (def.substring (ix + 1), encoding); } List & lt; String & gt; List = params.gate (name); If (list == null) {list = new ArrayList & lt; String & gt; (); Parms.put (name, list); } List.add (value); }  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -