2013-07-01 21 views
0

我正在嘗試將XML數據發佈到處理此XML的服務器,並給出響應,有時XML數據可能非常大,服務器需要一段時間來處理它,在這種情況下,我沒有得到任何迴應,而是收到IOException異常,並顯示消息「來自服務器的文件意外結束」。我很肯定發送到服務器的XML沒有錯誤,有沒有什麼我可以在我的最終確保這不會發生,或者這是一個服務器端問題?以下是我調用發佈數據的方法的代碼片段。Java IOException發佈大型數據時發生「文件意外從服務器端結束」

謝謝。

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

回答

0

沒有太多可以從客戶端來完成,它只是一個服務器端的問題,其中服務器需要很長時間來處理這會導致服務器連接超時之前它可以發送響應的數據。

相關問題