隨筆-6  評(píng)論-1  文章-0  trackbacks-0
          URL url = new URL("提交的URL");
           HttpURLConnection connection = (HttpURLConnection) url.openConnection();
           try
           {
            connection.setDoInput(true);
            connection.setDoOutput(true);
            {
             // 提交的內(nèi)容
             byte[] requsetContent = new byte[1024];
             connection.setRequestProperty("Content-Length", Integer.toString(requsetContent.length));
             OutputStream outputStream = connection.getOutputStream();
             try
             {
              // 向外輸入流
              outputStream.write(requsetContent);
              outputStream.flush();
             }
             catch (Exception ex)
             {
              throw ex;
             }
             finally
             {
              outputStream.close();
             }
            }
            // 獲取HTTP相應(yīng)請(qǐng)求
            int responseCode = connection.getResponseCode();
            String responseMessage = connection.getResponseMessage();
            {
             ByteArrayOutputStream baos = new ByteArrayOutputStream(1024 * 64);
             // 得到返回流
             InputStream inputStream = connection.getInputStream();
             try
             {
              byte[] buf = new byte[1024 * 64];
              int n;
              while ((n = inputStream.read(buf)) >= 0)
              {
               baos.write(buf, 0, n);
              }
             }
             catch (Exception ex)
             {
              ex.printStackTrace();
             }
             finally
             {
              inputStream.close();
             }
             // 獲取包的內(nèi)容
             byte[] responseContent = baos.toByteArray();
            }
           }
           catch (Exception ex)
           {
            throw ex;
           }
           finally
           {
            connection.disconnect();
           }
          posted on 2008-04-29 15:32 天堂有路 閱讀(847) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 湖州市| 广丰县| 开平市| 溧阳市| 南阳市| 玛沁县| 宜昌市| 台北市| 加查县| 大安市| 霍城县| 门头沟区| 昌邑市| 巧家县| 连南| 酒泉市| 新绛县| 临朐县| 惠来县| 黄石市| 鄂尔多斯市| 嵊泗县| 东光县| 介休市| 兰西县| 甘谷县| 锡林郭勒盟| 伊通| 长葛市| 卢龙县| 静宁县| 原阳县| 滦南县| 邹城市| 五大连池市| 桑植县| 绵竹市| 麻栗坡县| 平遥县| 高阳县| 莎车县|