我目前正在使用这样的东西:
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();
有了这个,我设法将一些数据传递到我的服务器。我现在想知道这种方式能寄多少?
我想发送一些 xml 文件(100-200 行长),想知道我是否可以这样做?
杰森
最佳答案
帖子主体(通常不称为参数,因为这通常意味着它与 URL 一起传递)可以是任意长度,仅受配置限制。
由于 POST 用于实现文件上传,因此大多数系统都允许相当大的主体。 100-200 行应该不是问题,除了最偏执的配置。
关于java - httpURL连接 : how long can a post argument be?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4780760/