Java客户端无法从wcf rest服务中读取大的响应

问题描述 投票:1回答:1

我试图在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>
java android httpwebrequest wcf
1个回答
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);
© www.soinside.com 2019 - 2024. All rights reserved.