URL url = new URL("http://www.baidu.com");
         URLConnection connection = (HttpURLConnection)url.openConnection();
         connection.setRequestProperty( " User-agent " , " IE/7.0 " ); 
         connection.connect();
 BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(),"Shift_JIS"));//根据对应编码接收                           
         String line = null ;
         StringBuilder sb = new StringBuilder();
          while ((line = in.readLine()) != null ) {
             sb.append(line);
         } 
         in.close(); 
         String trans=sb.toString();
         System.out.print(trans);

解决方案 »

  1.   

    System.Net.WebClient client = new System.Net.WebClient();
    client.Headers.Add("user-agent", " IE/7.0 ");
    Stream data = client.OpenRead("http://www.baidu.com");
    StreamReader reader = new StreamReader(data,Encoding.Default);
    string s = reader.ReadToEnd();
    data.Close();
    reader.Close();
    //Response.Write(s);
      

  2.   

    StreamReader reader=new StreamReader(data,Encoding.Default);
    这里的Encoding.Default怎样换成可以用自动获取目标语言的编码
      String charset = getCharsetFromLangpair(langpair);//自动获取目标语言的编码    public static final String LANGPAIR_EN_JA = " en|ja " ; // 英语到日语
         public static final String CHARSET_CN = " GBK " ;
         public static final String CHARSET_JA = " Shift_JIS " ;  private String getCharsetFromLangpair(String langpair) {
             if (langpair.equals(LANGPAIR_EN_JA))
                 return CHARSET_JA;          
             else return CHARSET_CN;
         } 
      

  3.   

    http://www.artinsoft.com/do_home.aspx