ÂÛ̳½»Á÷
Ê×Ò³°ì¹«×Ô¶¯»¯| ÍøÒ³ÖÆ×÷| ƽÃæÉè¼Æ| ¶¯»­ÖÆ×÷| Êý¾Ý¿â¿ª·¢| ³ÌÐòÉè¼Æ| È«²¿ÊÓƵ½Ì³Ì
Ó¦ÓÃÊÓƵ: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
±à³ÌÊÓƵ: CÓïÑÔÊÓƵ½Ì³Ì | HTML | Div+Css²¼¾Ö | Javascript | AccessÊý¾Ý¿â | Asp | Sql ServerÊý¾Ý¿âAsp.net  | Flash AS
µ±Ç°Î»Öà > ÎÄ×Ö½Ì³Ì > Asp.net½Ì³Ì
Tag:¾²Ì¬Ò³Ãæ,treeview,gridview,repeater,dataset,sqldatareader,ado.net,ÉÏ´«,Èý²ã,ajax,xml,ÁôÑÔ±¾,ÐÂÎÅ·¢²¼,É̳Ç,×¢Èë,´æ´¢¹ý³Ì,·ÖÒ³,°²È«,ÓÅ»¯,xmlhttp,fso,jmail,application,session,·ÀµÁÁ´,stream,ÎÞ×é¼þ,×é¼þ,md5,ÂÒÂë,»º´æ,¼ÓÃÜ,ÑéÖ¤Âë,Ëã·¨,cookies,ubb,ÕýÔò±í´ïʽ,ˮӡ,Ë÷Òý,ÈÕÖ¾,ѹËõ,base64,urlÖØд,¿Ø¼þ,Web.config,JDBC,º¯Êý,ÄÚ´æ,PDF,ǨÒÆ,½á¹¹,Æƽâ,±àÒë,ÅäÖÃ,½ø³Ì,·Ö´Ê,IIS,´¥·¢Æ÷,socket,formÈÏÖ¤,µÇ¼,ÊÓƵ½Ì³Ì

ʹÓÃ.NETʵÏֶϵãÐø´«

ÎÄÕÂÀà±ð£ºAsp.net | ·¢±íÈÕÆÚ:2008-10-5 22:14:04

ivy_live521£¨Ô­×÷£©

¶ÏµãÐø´«µÄÔ­Àí
ÔÚÁ˽âHTTP¶ÏµãÐø´«µÄÔ­Àí֮ǰ£¬ÏÈÀ´ËµËµHTTPЭÒ飬HTTPЭÒéÊÇÒ»ÖÖ»ùÓÚtcpµÄ¼òµ¥Ð­Ò飬·ÖΪÇëÇóºÍ»Ø¸´Á½ÖÖ¡£ÇëÇóЭÒéÊÇÓÉ¿Í»§»ú(ä¯ÀÀÆ÷)Ïò·þÎñÆ÷£¨WEB SERVER£©Ìá½»ÇëÇóʱ·¢Ëͱ¨ÎĵÄЭÒé¡£»Ø¸´Ð­ÒéÊÇÓÉ·þÎñÆ÷(web server)£¬Ïò¿Í»§»ú(ä¯ÀÀÆ÷)»Ø¸´±¨ÎÄʱµÄЭÒé¡£ÇëÇóºÍ»Ø¸´Ð­Ò鶼ÓÉÍ·ºÍÌå×é³É¡£Í·ºÍÌåÖ®¼äÒÔÒ»ÐпÕÐÐΪ·Ö¸ô¡£

 

ÒÔÏÂÊÇÒ»¸öÇëÇó±¨ÎÄÓëÏàÓ¦µÄ»Ø¸´±¨ÎĵÄÀý×Ó£º

GET /image/index_r4_c1.jpg HTTP/1.1

Accept: */*

Referer: http://192.168.3.120:8080

Accept-Language: zh-cn

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)

Host: 192.168.3.120:8080

Connection: Keep-Alive

 

 

HTTP/1.1 200 OK

Server: Microsoft-IIS/5.0

Date: Tue, 24 Jun 2003 05:39:40 GMT

Content-Type: image/jpeg

Accept-Ranges: bytes

Last-Modified: Thu, 23 May 2002 03:05:40 GMT

ETag: "bec48eb862c21:934"

Content-Length: 2827

 

ÿ? JFIF  H H  ÿ C [1]

¡­.

 

ÏÂÃæÎÒÃǾÍÀ´ËµËµ¡°¶ÏµãÐø´«¡±¡£

¹ËÃû˼Ò壬¶ÏµãÐø´«¾ÍÊÇÔÚÉÏÒ»´ÎÏÂÔØʱ¶Ï¿ªµÄλÖÿªÊ¼¼ÌÐøÏÂÔØ¡£ÔÚHTTPЭÒéÖУ¬¿ÉÒÔÔÚÇëÇó±¨ÎÄÍ·ÖмÓÈëRange¶Î£¬À´±íʾ¿Í»§»úÏ£Íû´ÓºÎ´¦¼ÌÐøÏÂÔØ¡£

±ÈÈç˵´ÓµÚ1024×Ö½Ú¿ªÊ¼ÏÂÔØ£¬ÇëÇó±¨ÎÄÈçÏ£º

 

GET /image/index_r4_c1.jpg HTTP/1.1

Accept: */*

Referer: http://192.168.3.120:8080

Accept-Language: zh-cn

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)

Host: 192.168.3.120:8080

Range:bytes=1024-

Connection: Keep-Alive

 

.NETÖеÄÏà¹ØÀà
Ã÷°×ÁËÉÏÃæµÄÔ­Àí£¬ÄÇô£¬ÎÒÃÇÀ´¿´¿´.NET FRAMEWORKÖÐΪÎÒÃÇÌṩÁËÄÄЩÀà¿ÉÒÔÀ´×öÕâЩÊ¡£

Íê³ÉHTTPÇëÇó
System.Net.HttpWebRequest

HttpWebRequest Àà¶Ô WebRequest Öж¨ÒåµÄÊôÐԺͷ½·¨Ìṩ֧³Ö£¬Ò²¶ÔʹÓû§Äܹ»Ö±½ÓÓëʹÓà HTTP µÄ·þÎñÆ÷½»»¥µÄ¸½¼ÓÊôÐԺͷ½·¨Ìṩ֧³Ö¡£

HttpWebRequest ½«·¢Ë͵½ Internet ×ÊÔ´µÄ¹«¹² HTTP ±êÍ·Öµ¹«¿ªÎªÊôÐÔ£¬ÓÉ·½·¨»òϵͳÉèÖá£Ï±í°üº¬ÍêÕûÁÐ±í¡£¿ÉÒÔ½« Headers ÊôÐÔÖеÄÆäËû±êÍ·ÉèÖÃΪÃû³Æ/Öµ¶Ô¡£µ«ÊÇ×¢Ò⣬ijЩ¹«¹²±êÍ·±»ÊÓΪÊÜÏÞÖƵģ¬ËüÃÇ»òÕßÖ±½ÓÓÉ API¹«¿ª£¬»òÕßÊܵ½ÏµÍ³±£»¤£¬²»Äܱ»¸ü¸Ä¡£RangeÒ²ÊôÓÚ±»±£»¤Ö®ÁУ¬²»¹ý£¬.NETΪ¿ª·¢ÕßÌṩÁ˸ü·½±ãµÄ²Ù×÷£¬¾ÍÊÇ AddRange·½·¨£¬ÏòÇëÇóÌí¼Ó´ÓÇëÇóÊý¾ÝµÄ¿ªÊ¼´¦»ò½áÊø´¦µÄÌض¨·¶Î§µÄ×Ö½Ú·¶Î§±êÍ·

Íê³ÉÎļþ·ÃÎÊ
System.IO.FileStream

FileStream ¶ÔÏóÖ§³ÖʹÓÃSeek·½·¨¶ÔÎļþ½øÐÐËæ»ú·ÃÎÊ, Seek ÔÊÐí½«¶ÁÈ¡/дÈëλÖÃÒƶ¯µ½ÎļþÖеÄÈÎÒâλÖá£ÕâÊÇͨ¹ý×Ö½ÚÆ«ÒƲο¼µã²ÎÊýÍê³ÉµÄ¡£×Ö½ÚÆ«ÒÆÁ¿ÊÇÏà¶ÔÓÚ²éÕҲο¼µã¶øÑԵģ¬¸Ã²Î¿¼µã¿ÉÒÔÊÇ»ù´¡ÎļþµÄ¿ªÊ¼¡¢µ±Ç°Î»Öûò½á⣬·Ö±ðÓÉSeekOriginÀàµÄÈý¸öÊôÐÔ±íʾ¡£

 

´úÂëʵÏÖ
Á˽âÁË.NETÌṩµÄÏà¹ØµÄÀ࣬ÄÇô£¬ÎÒÃǾͿÉÒÔ·½±ãµÄʵÏÖÁË¡£

´úÂëÈçÏ£º

 

static void Main(string[] args)

              {

                    

                     string StrFileName="c:\\aa.zip";      //¸ù¾Ýʵ¼ÊÇé¿öÉèÖÃ

                     string StrUrl="http://www.xxxx.cn/xxxxx.zip";   //¸ù¾Ýʵ¼ÊÇé¿öÉèÖÃ

 

                     //´ò¿ªÉÏ´ÎÏÂÔصÄÎļþ»òн¨Îļþ

                     long lStartPos =0;

                     System.IO.FileStream fs;

                     if (System.IO.File.Exists(StrFileName))

                     {

                            fs= System.IO.File.OpenWrite(StrFileName);

                            lStartPos=fs.Length;

                            fs.Seek(lStartPos,System.IO.SeekOrigin.Current);   //Òƶ¯ÎļþÁ÷Öеĵ±Ç°Ö¸Õë

                     }

                     else

                     {

                            fs = new System.IO.FileStream(StrFileName,System.IO.FileMode.Create);

                            lStartPos =0;

                     }

                    

                     //´ò¿ªÍøÂçÁ¬½Ó

                     try

                     {

                            System.Net.HttpWebRequest request =(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(StrUrl);

                            if ( lStartPos>0)

                                   request.AddRange((int)lStartPos);    //ÉèÖÃRangeÖµ

                           

                            //Ïò·þÎñÆ÷ÇëÇ󣬻ñµÃ·þÎñÆ÷»ØÓ¦Êý¾ÝÁ÷

                            System.IO.Stream ns= request.GetResponse().GetResponseStream();

 

                            byte[] nbytes = new byte[512];

                            int nReadSize=0;

                            nReadSize=ns.Read(nbytes,0,512);

                            while( nReadSize >0)

                            {

                                   fs.Write(nbytes,0,nReadSize);

                                   nReadSize=ns.Read(nbytes,0,512);

                            }

                            fs.Close();

                            ns.Close();

                            Console.WriteLine("ÏÂÔØÍê³É");

                     }

                     catch(Exception ex)

                     {

                            fs.Close();

                            Console.WriteLine("ÏÂÔعý³ÌÖгöÏÖ´íÎó:"+ex.ToString());

                     }

              }

 

ÒÔÉÏÊDZ¾ÈËÔÚ¿ª·¢ÖеÄÒ»µãССÌåÑ飬ϣÍûÄÜÓë´ó¼Ò·ÖÏí£¡ £º£©

 

×¢£º±¾ÎÄδ¾­Ðí¿É£¬²»µÃתÔØ

 

 

ÊÓƵ½Ì³ÌÁбí
ÎÄÕ½̳ÌËÑË÷
 
Asp.netÍƼö½Ì³Ì
Asp.netÈÈÃŽ̳Ì
¿´È«²¿ÊÓƵ½Ì³Ì
¹ºÂò·½Ê½/¼Û¸ñ
¹ºÂòÊÓƵ½Ì³Ì: ×Éѯ¿Í·þ
tel:15972130058