2012-07-12 142 views
0

我有以下的代碼來調用網址:http://10.105.0.120/24online/servlet/ClientRegistrationResponse?action=response&phone=919638983856&actioncode=0000產生java.io.IOException:服務器返回的HTTP響應代碼:500網址

代碼:

StringBuffer request=new StringBuffer(); 
      request.append(xml); 
      URL url = new URL(url); 
      HttpURLConnection obj = null; 
       obj = (HttpURLConnection)url.openConnection(); //create a SSL connection object server-to-server 

       ((URLConnection)obj).setDoInput(true); 
       ((URLConnection)obj).setDoOutput(true); 
       ((URLConnection)obj).setUseCaches(false); 
//    ((URLConnection)obj).setReadTimeout(10); 
       ((URLConnection)obj).setRequestProperty("Content-Type","application/x-www-form-urlencoded"); 
       obj.setRequestMethod("POST"); 
       obj.setRequestProperty("charset", "US-ASCII"); 
       //obj.setConnectTimeout(PropertyReader.IN_REQUEST_TIMEOUT); 
       //obj.setReadTimeout(PropertyReader.IN_REQUEST_TIMEOUT); 
       // Here the HTTPS request URL is created 

       DataOutputStream dataoutputstream = new DataOutputStream(((URLConnection)obj).getOutputStream()); 
       dataoutputstream.writeBytes(request.toString()); //request 
       //dataoutputstream.flush(); 
       dataoutputstream.close(); //connection closed 
       BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(((URLConnection)obj).getInputStream())); 
       String res = ""; 

           while ((res = bufferedreader.readLine()) != null) { 

        conresponse += res; 
       } 
       bufferedreader.close(); 

但我得到以下錯誤:

java.io.IOException: Server returned HTTP response code: 500 for URL: http://10.105.0.120/24online/servlet/ClientRegistrationResponse?action=response&phone=919638983856&actioncode=0000 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1313) 
    at cyberoam.corporate.integration.XMLSenderReceiver.sendFileData1(XMLSenderReceiver.java:70) 
    at cyberoam.corporate.modes.TopupRequestThread.sendTopupRequest(TopupRequestThread.java:56) 
    at cyberoam.corporate.modes.TopupRequestThread.run(TopupRequestThread.java:31) 
org.jdom.input.JDOMParseException: Error on line -1: Premature end of file. 
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:504) 
    at cyberoam.corporate.integration.XMLProcessor.parseXML(XMLProcessor.java:392) 
    at cyberoam.corporate.modes.TopupRequestThread.sendTopupRequest(TopupRequestThread.java:62) 
    at cyberoam.corporate.modes.TopupRequestThread.run(TopupRequestThread.java:31) 
Caused by: org.xml.sax.SAXParseException: Premature end of file. 
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) 
    at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) 
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) 
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:489) 
    ... 3 more 
Caused by: org.xml.sax.SAXParseException: Premature end of file. 
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) 
    at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) 
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) 
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:489) 
    at cyberoam.corporate.integration.XMLProcessor.parseXML(XMLProcessor.java:392) 
    at cyberoam.corporate.modes.TopupRequestThread.sendTopupRequest(TopupRequestThread.java:62) 
    at cyberoam.corporate.modes.TopupRequestThread.run(TopupRequestThread.java:31) 
Caused by: org.xml.sax.SAXParseException: Premature end of file. 
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) 
    at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) 
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) 
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:489) 
    at cyberoam.corporate.integration.XMLProcessor.parseXML(XMLProcessor.java:392) 
    at cyberoam.corporate.modes.TopupRequestThread.sendTopupRequest(TopupRequestThread.java:62) 
    at cyberoam.corporate.modes.TopupRequestThread.run(TopupRequestThread.java:31) 
2012-07-12 18:52:49,416 - PIPE_COMM: In Receiving Object for /usr/local/nas/pipes/raam_to_gui_pipe 
******************SMPPThread constructor called***************** 

這個錯誤的原因是什麼?因爲當我從瀏覽器直接調用URL時,它的工作非常完美。

+0

這很好,問題是什麼? – biziclop 2012-07-12 13:57:00

+0

對不完整的問題感到抱歉,請檢查我編輯的問題 – chetan 2012-07-12 13:59:47

回答

1

有問題嗎?

您向服務器發送了錯誤的請求,並且它正在響應內部服務器錯誤(代碼500)。合乎邏輯的事情是檢查你的HTTP服務器日誌(它是一個10 * IP地址,所以它對你來說是本地的)。

此外,JDOM異常處於不同的線程或其他東西....在您顯示的代碼中沒有與JDOM相關的代碼,異常堆棧跟蹤沒有以任何方式鏈接到具有500狀態響應的IOException 。或者,您忽略了status-500響應(IOException),然後期望同一線程中的JDOM代碼從服務器解析(可能是空的)錯誤響應(這無疑會以過早結束的方式結束)文件)。

您需要:

  • 檢查你的服務器日誌
  • 處理所有異常適當
  • 可能添加一些調試代碼,使您可以檢查您發送到數據從服務器/檢索。
相關問題