随笔-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 小小程序程序员混口饭吃 阅读(4057) 评论(0)  编辑  收藏 所属分类: java

只有注册用户登录后才能发表评论。


网站导航: