隨筆-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
          主站蜘蛛池模板: 长武县| 佛坪县| 静海县| 隆德县| 红安县| 博野县| 神池县| 卓尼县| 西昌市| 稷山县| 彭泽县| 浦城县| 镇原县| 开江县| 乌拉特前旗| 惠东县| 沅江市| 霍州市| 外汇| 成安县| 乌拉特前旗| 阳原县| 苏尼特左旗| 清苑县| 玛沁县| 南雄市| 淮阳县| 衡水市| 北流市| 桦甸市| 康定县| 霸州市| 花垣县| 贡嘎县| 宁波市| 大荔县| 昭苏县| 斗六市| 北宁市| 盘山县| 萝北县|