4

I['m currently using something like this

 HttpURLConnection con = (HttpURLConnection) u.openConnection ();
     con.setDoInput(true);
     con.setRequestMethod("POST");

     con.setDoInput (true);
     con.setDoOutput (true);
     con.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");

        out = new DataOutputStream(con.getOutputStream());
     String content = "username=" + URLEncoder.encode ("bob")
      + "&password=" + URLEncoder.encode ("smith");
     System.out.println("\n" + "sending form to HTTP server ...");
     out.writeBytes (content);
     out.flush ();
     out.close ();

     con.connect();

With this I manage to pass some data to my server. what I'm now wandering is how much can be send this way ?

I want to be able to send some xml files (100~200 lines long) and would like to know if I can you this?

Jason

Jason Rogers
  • 18,658
  • 25
  • 74
  • 110
  • You should in fact be using `multipart/form-data` encoding. See also http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests – BalusC Jan 24 '11 at 12:15

3 Answers3

5

The post body (it's not usually called an argument, since that usually implies it being passed with the URL) can be any length, restricted only by configuration.

Since POST is used to implement file uploads, most systems allow pretty large bodies. 100-200 lines should not be a problem at all, except for the most paranoid configurations out there.

Joachim Sauer
  • 278,207
  • 54
  • 523
  • 586
2

Any length, just keep in mind that your request can timeout. GET data is limited to 4096 bytes.

Ilya Saunkin
  • 16,376
  • 9
  • 34
  • 50
  • GET limit is mainly dependent on webbrowser used and it's not explicitly 4096. Even more, HTTP spec states a safe limit of 255. See also http://stackoverflow.com/questions/2659952/maximum-length-of-http-get-request – BalusC Jan 24 '11 at 12:16
  • Actually yeah, 4096 I said having in mind a particular configuration, you are right. What you say about 255, that's for URL's, not for requests where you GET request params. – Ilya Saunkin Jan 24 '11 at 12:46
2

The maximum length of a post is usually configured in the server configuration, not on client-side.

stacker
  • 64,199
  • 27
  • 132
  • 206