浅论使用http协议和winsockapi实现webzip文件-计算机应用程计算机应用程序论文
浅论使用http协议和winsockapi实现webzip文件下载-计算机应用程_计算机应用程序论文本方法主要涉及以下四方面知识摘要:html语言、http协议、winsock编程、多线程程序设计。
httpwinsockapiwebzip-_ 浅论使用协议和实现文件下载计算机应用程计算机应用程序论文 htmlhttpwinsock 本方法主要涉及以下四方面知识摘要:语言、协议、编程、多线程程序设 1.a 计。程序实现过程摘要:分析链接关系(限于篇幅,这里只先容对锚标记〈〉 htmlaahref=″...″name=″...″target=″...″ 的分析)。在中〈〉标记的基本语法为摘要:〈〉。 hrefurl2.http 其中参数的值就是欲获取的值。下载。在协议中常用的请求方法有 getpostgetgetget 两种摘要:和。本实现使用方法。最简化的请求包如下摘要: /index.htmhttp/1.1“/index.htm”“http/1.1” 表示客户端欲下载的文件路径;表示协议版本。程 getweb80tcp 序天生请求包,在成功连接对应服务器的或其它端口后,使用基于协议的 同步模式套接字发送请求包并等待返回信息。服务器将返回一个应答包,大致如下摘要: http/1.0200ok...[... 数据第一行是应答信息。假如成功,服务器将返回 “http/1.0200ok”http() 。第三行是一个空行,用以分隔包头和包体数据。第四行开 http 始就是以字节流的方式返回的数据。假如使用代理,则和上述有两点不同。第 web 一,连接时应连接代理服务器,而不是连接服务器。第二,在天生请求包时,下 urlurl“gethttp://netsport/index.htmhttp/1.1” 载文件的必须写全。对上例而言,请求应为摘要, “get/index.htmhttp/1.1”(delphi3.0)1. 而不是。具体程序和类程序使用编制摘要: winsockproceduretform1.formcreate(sender:tobject);var 初始化。摘要 wversionrequired:word;wsdata:twsadata;beginismultithread 摘要摘要摘 :=true;//″″″″wversionrequired:=makeword(2,0);case 要置支持多线程为真摘要 wsastartup(wversionrequired,wsdata)of//winsockwsasysnotready: 初始化摘要 application.messagebox(′′,′′,mb_ok);wsavernotsupported: 网络系统未预备信息摘要 application.messagebox(′′,′′,mb_ok);wsaeinval: 未提供网络接口信息摘要 application.messagebox(′′,′′,mb_ok);end;end;2. 网络版本不被支持信息文件 tdownfilethread=class(tthread)privatefileurl:string;// 下载线程。摘要记录 urlprotectedprocedureexecute;override;publicconstructorcreate(url 文件的摘 :string);end;constructortdownfilethread.create(url:string);beginfileurl 要摘要 :=url;freeonterminate:=true;inheritedcreate(false);end;procedure 摘要摘要 tdownfilethread.execute;var mysocket:tsocket;myclient:tsockaddr;recvbuf:array[0..332ofchar; 摘要摘要摘要 mycmdstr:string;ptemp:pchar;myhandle,index_ch,reccount,i 摘要摘要摘 :integer;begin//socketmysocket:=socket(af_inet,sock_stream,0); 要创建本地摘要 if(mysocket=socket_error)thenbeginapplication.messagebox(′′,′ 初始化失败!信 ′,mb_ok); 息 exit;end;//myclient.sin_family:=af_inet; 天生连接主机的结构摘要 myclient.sin_port:=htons(connectedport);//connectedport 摘要摘要:全局变量,记录连 strpcopy(recvbuf,getserverip(fileurl));//getserverip(fileurl) 接端口号摘要:返回服务 ipmyclient.sin_addr.s_addr:=inet_addr(recvbuf);//if 器的摘要连接服务器

