简体   繁体   English

我们可以通过URLConnection传递多少数据。

[英]How much data we can pass through URLConnection.?

I am passing 10 students information from one Application to Other application in json format.I have to send 25 lacs studends information from one application to other application. 我将10个学生信息从一个应用程序传递给json格式的其他应用程序。我必须将25个lacs的学生信息从一个应用程序发送到其他应用程序。 I want to know, how much size of data i can send ? 我想知道,我可以发送多少大小的数据? how many students i can send in json format.? 我可以用json格式发送多少学生。
Below is code from sender application. 以下是发件人申请的代码。

    JSONObject jsonObject = new JSONObject();
    JSONArray jArray = new JSONArray();
    try {
        for (Student student : listStudent) {        
            JSONObject studentJSON = new JSONObject();
            studentJSON.put("First Name", student.getFirstName());
            studentJSON.put("Last Name", student.getLastName());
            jArray.put(studentJSON);
        }
        jsonObject.put("StudentArray", jArray);
        response.setContentType("application/json");
        response.getWriter().write(jsonObject.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }

Below is code from receiver application. 以下是接收器应用程序的代码。

     URL url = new URL("http:"//xyz.com);
     BufferedReader reader = new BufferedReader(newInputStreamReader(url.openStream()));
     JSONObject object = null ;
     String line=null;
     while ((line = reader.readLine()) != null) 
     {
       object= new JSONObject(line);
     }

URLConnection supports the HTTP Specification for HTTP connections. URLConnection支持HTTP连接的HTTP规范 I haven't really seen a max number of bytes that can be transferred via HTTP, but the size must match the header Content-Length if present. 我还没有看到可以通过HTTP传输的最大字节数,但是大小必须与标头Content-Length匹配(如果存在)。 Otherwise bytes will continue to be read until the connection is closed. 否则,将继续读取字节,直到连接关闭。

URLConnection treats the value of Content-Length as an int in Java 1.6 and earlier or a long in Java 1.7 and later, which would suggest that the maximum supported number of bytes in the body would be 2^31-1 bytes or 2^63-1 bytes, respectively, so long as Content-Length is being set. URLConnection将Content-Length的值视为Java 1.6及更早版本中的intJava 1.7及更高版本中的long ,这表明正文中支持的最大字节数为2 ^ 31-1字节或2 ^ 63只要-1个字节,只要设置Content-Length即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM