net 调用java 接口方式

private const string CST_DEFAULT_ENCODEING = "GB2312" ;

public static string GetWebPageString(string URL)
  {
   Stream data = null ;
   try
   {                
    string str = "";
    string sReturn = "" ;
    // Get HTML data                   
    WebClient client = new WebClient();
        
    data = client.OpenRead(URL);
    StreamReader reader = new StreamReader(data, System.Text.Encoding.GetEncoding (CST_DEFAULT_ENCODEING)  );

    str = reader.ReadLine(); 
 
    while( str != null)
    {
     sReturn += str ;
     str = reader.ReadLine();
    }
    return sReturn; 
   }
   catch(WebException exp)
   {
    Debug.WriteLine(exp.Message, "WebException");
    throw  exp;
   }
   catch(Exception ex)
   {
    throw ex;
   }
   finally
   {
    if (data != null)    data.Close () ;
   }
        }

 

 

 

posted on 2010-01-14 14:09  http  阅读(226)  评论(0)    收藏  举报

导航