Java 客户端无法读取 WCF Rest 服务的大响应

发布于 2024-10-07 23:39:06 字数 1323 浏览 3 评论 0原文

我正在尝试在 android 2.1 上使用 java 客户端来使用 REST WCF 服务。 它非常适用于小的响应。当我尝试进一步获取 1000+ 字符响应 reader.read(buffer) 时,无法读取所有字符。这导致脚本的最后一行返回: JsonException untermerated string at character 8193 "{plate,...

在模拟器 android star 获取它之前,我的 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>

I am trying to consume a rest WCF service using java client on android 2.1.
It works perfectly on small responses. When i tried to push a little further by getting 1000+ char response reader.read(buffer) failed to read all the characters. This caused the last line of the script to return: JsonException unterminated string at character 8193 "{plate,...

My android device starts to get this error before the emulator android stars to get it (character 1194 instead of 8193). Anyone knows how get the full message?

Client Code:

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

Server Config:

<webHttpBinding>
    <binding name="big_webHttpBinding" maxReceivedMessageSize="4097152" maxBufferSize="4097152" maxBufferPoolSize="4097152">
      <readerQuotas maxStringContentLength="4097152" maxArrayLength="4097152" maxBytesPerRead="4097152" maxNameTableCharCount="4097152" maxDepth="4097152"/>
    </binding>
  </webHttpBinding>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绻影浮沉 2024-10-14 23:39:06

而不是

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

Instead of

char[] buffer = new char[(int)responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close(); 

do this:

String jsonText = EntityUtils.toString(responseEntity, HTTP.UTF_8);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文