隨筆-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 小小程序程序員混口飯吃 閱讀(4070) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 梧州市| 馆陶县| 新河县| 彭州市| 兰坪| 甘洛县| 礼泉县| 陆良县| 乳源| 安顺市| 岑溪市| 奈曼旗| 沙田区| 阿坝县| 信丰县| 体育| 广宁县| 绍兴县| 行唐县| 元谋县| 嘉定区| 赫章县| 综艺| 双城市| 桃源县| 海南省| 五家渠市| 武强县| 卢氏县| 西林县| 聂拉木县| 武平县| 林甸县| 仪征市| 阳曲县| 米脂县| 广汉市| 泰顺县| 伊通| 开封县| 青铜峡市|