Is there a convenient way to read and analyze data from an incoming request.
For example, a client request to send messages
URLConnection connection = new URL(url).openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); PrintWriter writer = null; try { OutputStream output = connection.getOutputStream(); writer = new PrintWriter(new OutputStreamWriter(output, charset), true); // true = autoFlush, important! // Send normal param. writer.println("--" + boundary); writer.println("Content-Disposition: form-data; name=\"param\""); writer.println("Content-Type: text/plain; charset=" + charset); writer.println(); writer.println(param);
I was unable to get the parameter using request.getParameter("paramName") . Following code
BufferedReader reader = new BufferedReader(new InputStreamReader( request.getInputStream())); StringBuilder sb = new StringBuilder(); for (String line; (line = reader.readLine()) != null;) { System.out.println(line); }
however displays content for me
-----------------------------29772313742745 Content-Disposition: form-data; name="name" J.Doe -----------------------------29772313742745 Content-Disposition: form-data; name="email" abuse@spamcop.com -----------------------------29772313742745
What is the best way to parse an incoming request? I do not want to write my own parser, maybe there is a ready-made solution.
java urlconnection servlets
atuser Jul 26 '10 at 16:57 2010-07-26 16:57
source share