最大 HttpUrlConnection 响应

Maximum HttpUrlConnection Response

我正在使用 HttpUrlConnection 从 Web 获取 JSON 字符串,但响应对于较小的字符串是好的,但对于较大的字符串则不然:this is what I am seeing in my app, and this 是从服务器到我做的网页的数据不包括来自服务器端的任何 HTML。

这是我的代码:

URL adr = new URL("http://placeform.tk/forapp.php");
HttpURLConnection connection =(HttpURLConnection) adr.openConnection();
connection.connect();
int rcode = connection.getResponseCode();
Log.d("rcode",Integer.toString(rcode));
if (rcode == HttpURLConnection.HTTP_OK) {
    InputStream inputStreamReader = connection.getInputStream();
    String c = connection.getHeaderField("content-length");
    Reader rd = new InputStreamReader(inputStreamReader);
    Log.d("contentsize", Integer.toString(connection.getContentLength()) + c);
    chars = new char[connection.getContentLength()];
    Log.d("contentsize", Integer.toString((int)connection.getContentLength()) + c);
    rd.read(chars);
    String output = new String(chars);

使用 this link 并在您的项目中添加 class 并从 class 调用网络服务。因为 class 将使用字符串生成器构建您的响应字符串。看看 class。如果您有任何问题,请发表评论。