我试图在Android 2.1上使用java客户端使用其余的WCF服务。 它适用于小响应。当我试图通过获得1000+ char响应reader.read(缓冲区)无法读取所有字符时进一步推动。这导致脚本的最后一行返回:JsonException未终止的字符串,位于字符8193“{plate,...
我的android设备开始在模拟器android明星得到它之前得到这个错误(字符1194而不是8193)。任何人都知道如何获得完整的信息?
客户代码:
HttpGet request = new HttpGet(SERVICE_URI + "/GetPlates");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
char[] buffer = new char[(int)responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
JSONArray plates = new JSONArray(new String(buffer));
服务器配置:
<webHttpBinding>
<binding name="big_webHttpBinding" maxReceivedMessageSize="4097152" maxBufferSize="4097152" maxBufferPoolSize="4097152">
<readerQuotas maxStringContentLength="4097152" maxArrayLength="4097152" maxBytesPerRead="4097152" maxNameTableCharCount="4097152" maxDepth="4097152"/>
</binding>
</webHttpBinding>
答案 0 :(得分:5)
而不是
char[] buffer = new char[(int)responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
这样做:
String jsonText = EntityUtils.toString(responseEntity, HTTP.UTF_8);