YoshionTwo 2015-07-14 07:15 采纳率: 0%
浏览 1560

http协议系统之间交互,出现的编程的报错。我该怎样修改?求大神啊

现在我们系统跟gps之间交互,我采用的httpClient,可是每次跑程序的时候都会报错

 java.net.SocketException: Software caused connection abort: recv failed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(Unknown Source)
    at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
    at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:155)
    at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:284)
    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)

我的实现的代码

 public String sendMessage(String xmlMessage)throws Exception{

         // 创建默认的httpClient实例.     
               CloseableHttpClient httpclient = HttpClients.createDefault();  
               // 创建httppost     
                HttpPost httppost = new HttpPost("http://192.168.46.35:8080/BGpsWeb/gpsForeignInterface/shipLocation.do");  


         String responseMessage=null;
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        //formparams.add(new BasicNameValuePair("cqdd", xmlMessage));
        formparams.add(new BasicNameValuePair("cqdd", xmlMessage));
        UrlEncodedFormEntity entity;

        try {  
            entity = new UrlEncodedFormEntity(formparams, "GBK");
            httppost.setEntity(entity);  
            System.out.println("executing request " + httppost.getURI());  
            CloseableHttpResponse response = httpclient.execute(httppost);  
            try {  
                HttpEntity reEntity = response.getEntity();  
               if (entity != null) {  
                    System.out.println("--------------------------------------"); 
                    responseMessage=EntityUtils.toString(reEntity);
                   //System.out.println("Response content: " + EntityUtils.toString(reEntity, "UTF-8"));  
                    System.out.println("--------------------------------------");  
                }  
            } finally {  
                response.close();  
                }  
            } catch (ClientProtocolException e) {  
                e.printStackTrace();  
            } catch (UnsupportedEncodingException e1) {  
                e1.printStackTrace();  
            } catch (IOException e) {  
                e.printStackTrace();  
            } finally {  
                // 关闭连接,释放资源     
                try {  
                  httpclient.close();  
               } catch (IOException e) {  
                    e.printStackTrace();  
                }  
            }  

        return responseMessage;

    }

  • 写回答

2条回答 默认 最新

  • JPF1024 2015-07-14 07:26
    关注

    1.用本机电脑ping一下你要连接的地址是可用的嘛?

    2.需要长连接嘛?你那个错误,貌似是连接问题,有可能是网络不稳定造成的。

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?