gpt4 book ai didi

发布大数据时出现 Java IOException "Unexpected end of file from server"

转载 作者:行者123 更新时间:2023-12-01 14:22:48 25 4
gpt4 key购买 nike

我正在尝试将 XML 数据发布到处理此 XML 并给出响应的服务器,有时 XML 数据可能非常大,服务器需要一段时间来处理它,在这些情况下,我无法获取任何数据相反,我收到一个 IOException 响应,其中包含消息“来自服务器的文件意外结束”。我确信发送到服务器的 XML 没有充满错误,我能做些什么来确保这种情况不会发生吗?或者这是服务器端问题吗?下面是我调用的用于发布数据的方法的代码片段。

谢谢。

String encodedData="some XML"    
String urlString="example.com"
try {
URL url = new URL(urlString);
HttpURLConnection urlConnection;
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", contentType);
urlConnection.setRequestProperty("Content-Length", encodedData.length()+"");
OutputStream os = urlConnection.getOutputStream();
os.write(encodedData.getBytes());

BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "UTF-8"));
StringBuffer sb = new StringBuffer();
String inputLine;
while ((inputLine = in.readLine()) != null) {
sb.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
logger.debug("MalformedURLException " + e.getMessage());
logger.debug((new StringBuilder()).append("urlString=").append(urlString).toString());
throw (e);
} catch (IOException e) {
logger.debug("IOException " + e.getMessage());
logger.debug((new StringBuilder()).append("urlString=").append(urlString).toString());
throw (e);
}
return sb.toString();

最佳答案

客户端无能为力,这只是服务器端问题,服务器需要很长时间来处理数据,导致服务器连接在发送响应之前超时。

关于发布大数据时出现 Java IOException "Unexpected end of file from server",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17405325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com