简体   繁体   English

发布大数据时,Java IOException“服务器中的文件意外结束”

[英]Java IOException “Unexpected end of file from server” when posting large data

I am trying to post XML data to a server which processes this XML and gives a response back, some times the XML data can be very large and the server takes a while to process it, in those cases i fail to get any response back instead i receive a IOException with the message "Unexpected end of file from server". 我试图将XML数据发布到处理该XML并返回响应的服务器,有时XML数据可能非常大,服务器需要一些时间来处理它,在这种情况下,我无法获得任何响应我收到一条IOException,消息为“来自服务器的文件意外结束”。 I am positive the XML being sent to the server is not full of errors, is there anything i can do on my end to make sure this doesn't happen or is this a server side issue? 我确信发送到服务器的XML不会充满错误,我可以做些什么来确保这不会发生,或者这是服务器端的问题吗? Below is code fragment of the method i call to post the data. 以下是我调用的用于发布数据的方法的代码片段。

Thanks. 谢谢。

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

客户端无法做很多事情,这只是服务器端的问题,其中服务器需要很长时间来处理数据,这导致服务器在发送响应之前连接超时。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Solr SimplePostTool:读取响应时出现IOException:java.net.SocketException:服务器中的文件意外结束 - Solr SimplePostTool: IOException while reading response: java.net.SocketException: Unexpected end of file from server java.io.IOException when posting multipart/form-data from Firefox 74 / 75 and using Apache AJP connector on server side - java.io.IOException when posting multipart/form-data from Firefox 74 / 75 and using Apache AJP connector on server side Java HTTP Server错误:服务器中的文件意外结束 - Error with Java HTTP Server: Unexpected end of file from server java.net.SocketException:来自服务器的文件意外结束 - java.net.SocketException: Unexpected end of file from server 引起:java.net.SocketException:来自服务器的文件意外结束 - Caused by: java.net.SocketException: Unexpected end of file from server 异常:java.net.SocketException:来自服务器的文件意外结束 - Exception: java.net.SocketException: Unexpected end of file from server `java.io.StreamCorruptedException:从文件中读取某些对象时意外的块数据结束 - `java.io.StreamCorruptedException: unexpected end of block data` when reading certain objects from file java.io.IOException:意外的流结束 - java.io.IOException: unexpected end of stream 如何处理“来自服务器的文件意外结束”? - how to deal with “Unexpected end of file from server”? Java简单代码:java.net.SocketException:来自服务器的文件意外结束 - Java simple code: java.net.SocketException: Unexpected end of file from server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM