隨筆-109  評論-187  文章-25  trackbacks-0
          import java.io.BufferedReader;
          import java.io.DataOutputStream;
          import java.io.IOException;
          import java.io.InputStream;
          import java.io.InputStreamReader;
          import java.net.HttpURLConnection;
          import java.net.MalformedURLException;
          import java.net.URL;

          public class TestConn {

              
          public TestConn() {
                  
          super();
              }


              
          public static void main(String[] args) throws Exception {
                  String url 
          = null;
                  getHttpText(url);
                  System.out.println(
          "abc");
              }


              
          public static String getHttpText(String str) {
                  URL url 
          = null;
                  
          try {
                      url 
          = new URL(str);
                  }
           catch (MalformedURLException e) {
                      e.printStackTrace();
                  }

                  HttpURLConnection huc 
          = null;
                  
          try {

                      huc 
          = (HttpURLConnection) url.openConnection();
                      huc.setRequestMethod(
          "GET");
                      huc.setRequestProperty(
          "Content-Type",
                              
          "application/vnd.syncml.dm+xml");
                      
          // application/x-www-form-urlencoded
                      
          // application/vnd.syncml.dm+xml
                      huc.setDoOutput(true);
                      huc.setRequestProperty(
          "Cache-Control""private");
                      huc.setRequestProperty(
          "Accept-Charset""utf-8");
                      huc.setRequestProperty(
          "Accept""application/vnd.syncml.dm+xml");
                      huc.setRequestProperty(
          "Content-Length""3");
                      DataOutputStream printout;
                      printout 
          = new DataOutputStream(huc.getOutputStream());
                      printout.writeBytes(
          "abc");
                  }
           catch (IOException e) {
                      e.printStackTrace();
                  }

                  InputStream is 
          = null;
                  
          try {
                      is 
          = huc.getInputStream();
                  }
           catch (IOException e) {
                      e.printStackTrace();
                  }

                  BufferedReader br 
          = new BufferedReader(new InputStreamReader(is));
                  StringBuffer sb 
          = new StringBuffer();
                  String line 
          = "";
                  
          try {
                      
          while ((line = br.readLine()) != null{
                          sb.append(line).append(
          "\n");
                      }

                  }
           catch (IOException e) {
                      e.printStackTrace();
                  }

                  
          return sb.toString();
              }


          }

          posted on 2007-05-14 09:16 小小程序程序員混口飯吃 閱讀(4071) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 漳平市| 高青县| 新沂市| 莱西市| 陕西省| 调兵山市| 治县。| 张家界市| 南部县| 镇康县| 尼木县| 浏阳市| 荣昌县| 鄂托克前旗| 宁远县| 辉县市| 威宁| 夏河县| 鄄城县| 翁牛特旗| 石阡县| 迁安市| 彭泽县| 武冈市| 临城县| 凉城县| 滦南县| 天长市| 会同县| 西峡县| 伊宁县| 巴青县| 兴城市| 霍林郭勒市| 宁国市| 临西县| 西乡县| 绿春县| 韶关市| 河曲县| 湘西|