-1

this simple post method didn't send anything to server(servlet). I can get, but i can't post!

@Override
        protected String doInBackground(String... params) {
            try {
                URL url = new URL("http://ipaddr:8080/work/wh");
                HttpURLConnection client = (HttpURLConnection) url.openConnection();
                client.setRequestMethod("POST");
                client.setDoOutput(true);
                client.setChunkedStreamingMode(0);
                client.connect();

                OutputStream outputStream = client.getOutputStream();
                PrintWriter pw = new PrintWriter(outputStream);
                pw.println(System.currentTimeMillis());
                pw.println(System.currentTimeMillis());
                pw.println(new Float(5.6));
                pw.println(new Integer(3));
                pw.println(new Integer(2));
                pw.println(new Integer(32));
                pw.println(new Integer(2));
                pw.close();
                outputStream.close();

            }catch(Exception e){
                Log.e("text", "ux " + e.getMessage());
            }
            return null;
        }

at server side if i tried to read any line new Scanner(request.getInputStream()).nextLine(); I get

NoSuchElementException: No line found

what do you think might be the problem?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Error
  • 820
  • 1
  • 11
  • 34
  • `NoSuchElementException` is not 'void'. – user207421 Jun 28 '16 at 06:37
  • i mean i get void object inputsteam has no data – Error Jun 28 '16 at 06:39
  • Code is not in MCVE format and the cause is not visible in the information provided so far, so we can only give educated guesses. Are you aware that the request body will be empty when it's already (implicitly) been parsed by the server beforehand? E.g. calling `request.getParameter()` will cause it to instantly be parsed. Nonetheless, why don't you just follow the default `application/x-www-form-urlencoded` format as used by HTML forms and natively supported by servlet API? See also http://stackoverflow.com/q/2793150 – BalusC Jun 28 '16 at 07:39

1 Answers1

-1

Try flushing PrintWritter/Outputstream before closing them.

Ankush G
  • 989
  • 9
  • 14