4

我目前正在使用这样的东西:

 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 行长)并且想知道我是否可以这样做?

杰森

4

3 回答 3

5

帖子正文(通常不称为参数,因为这通常意味着它与 URL 一起传递)可以是任意长度,仅受配置限制。

由于 POST 用于实现文件上传,因此大多数系统都允许相当大的主体。100-200 行根本不应该是一个问题,除了那里最偏执的配置。

于 2011-01-24T10:34:55.787 回答
2

任何长度,请记住您的请求可能会超时。GET 数据限制为 4096 字节。

于 2011-01-24T10:09:31.073 回答
2

帖子的最大长度通常在服务器配置中配置,而不是在客户端。

于 2011-01-24T10:11:41.843 回答