首页  编辑  

得到网络文件的大小和类型

Tags: /C#/Web网络编成/   Date Created:

private void button1_Click( object sender , EventArgs e)

{

    HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create(

        "http://community.csdn.net/Index.htm" );

   request . MaximumAutomaticRedirections = 4 ;

   request . MaximumResponseHeadersLength = 4 ;

   request . Credentials = CredentialCache . DefaultCredentials;

    HttpWebResponse response = ( HttpWebResponse )request . GetResponse();

    Console . WriteLine( "Content length is {0}" , response . ContentLength);

    Console . WriteLine( "Content type is {0}" , response . ContentType);

   response . Close();

}