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

时间:2015-04-16 12:38:57

标签: java json urlconnection

我将10个学生信息从一个应用程序传递给json格式的其他应用程序。我必须从一个应用程序向其他应用程序发送25个学生的学生信息。我想知道,我可以发送多少大小的数据?我可以用json格式发送多少学生。?
以下是来自发件人申请的代码。

    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();
    }

以下是接收器应用程序的代码。

     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);
     }

1 个答案:

答案 0 :(得分:0)

URLConnection支持HTTP连接的HTTP Specification。我还没有真正看到可以通过HTTP传输的最大字节数,但是如果存在,则大小必须与标题Content-Length相匹配。否则,将继续读取字节,直到连接关闭。

URLConnection将内容长度的值视为Java 1.6中的int以及Java 1.7及更晚的long,这表明只要设置了Content-Length,主体中支持的最大字节数将分别为2 ^ 31-1个字节或2 ^ 63-1个字节。

相关问题