当前位置: 代码迷 >> J2SE >> httpClient 错误 The server failed to respond with a valid HTTP response
  详细解决方案

httpClient 错误 The server failed to respond with a valid HTTP response

热度:10329   发布时间:2013-02-25 00:00:00.0
httpClient 异常 The server failed to respond with a valid HTTP response
使用 httpClient 从服务器端读取数据,出现异常 : 
Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response
执行的代码如下: 
Java code
public static String getResultByHttpGet()            throws ClientProtocolException, IOException    {        String result = "";                String url="http://192.168.1.83/imonitorint?op=r&33032=0";        HttpGet httpGet = new HttpGet();                //执行这行代码时出错        HttpResponse response = new DefaultHttpClient().execute(httpGet);        if (response.getStatusLine().getStatusCode() == 200)        {            HttpEntity entity = response.getEntity();            result = EntityUtils.toString(entity, "GB2312");        }        return result;    }

全部的错误信息如下: 

org.apache.http.client.ClientProtocolException
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:822)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
at com.osee.yws.httpAgreement.HttpAgreement.getResultByHttpGet(HttpAgreement.java:50)
at com.osee.yws.bll.LCDOptionBll.readLcdOption(LCDOptionBll.java:104)
at com.osee.yws.bll.LCDOptionBll.readInput(LCDOptionBll.java:73)
at com.osee.yws.gui.SetDeviceOptionLCD$1.windowOpened(SetDeviceOptionLCD.java:74)
at java.awt.AWTEventMulticaster.windowOpened(Unknown Source)
at java.awt.AWTEventMulticaster.windowOpened(Unknown Source)
at java.awt.Window.processWindowEvent(Unknown Source)
at javax.swing.JDialog.processWindowEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response
at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:109)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:252)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:281)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247)
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:219)
  相关解决方案