文件下载程序--AfxParseURL

本文介绍了VC++中用于文件下载的AfxParseURL函数,详细解析了函数参数和使用示例,展示了如何通过该函数获取URL的服务类型、服务器名、对象以及端口号。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 偶尔看到一个用vc++编写的文件下载程序,为了对其有更深的认识,下面作一点小小分析,不适之处还望见谅。

第一步:分析AfxParseURL函数。

原型:BOOL AFXAPI AfxParseURL(LPCTSTR pstrURL,DWORD& dwServiceType,CString& strServer,CString& strObject,INTERNET_PORT& nPort);

解释:pstrURL:            A pointer to a string containing the URL to be parsed.

            dwServiceType:Indicates the type of Internet service. Possible values are as follows: (只列出几个值,相见MSDN)

AFX_INET_SERVICE_FTP
AFX_INET_SERVICE_HTTP
AFX_INET_SERVICE_HTTPS
AFX_INET_SERVICE_GOPHER

            strServer:          The first segment of the URL following the service type.

            strObject:          An object that the URL refers to (may be empty).

            nPort:                Determined from either the Server or Object portions of the URL, if either exists.

应用实例:(环境:vc 6.0)

#include "afxinet.h"
#include "iostream"
using namespace std;
int main()
{
           LPCTSTR url="http://image.baidu.com/donghua.gif";  //typedef CONST CHAR *LPCSTR, *PCSTR;
                                                                                                           //typedef LPCSTR LPCTSTR;
           DWORD dwServiceType;//typedef unsigned long  DWORD;
           CString strServer;
           CString strObject;
           INTERNET_PORT nPort;       //typedef unsigned short WORD;
                                                               //typedef WORD INTERNET_PORT;
           AfxParseURL(url,dwServiceType,strServer,strObject,nPort);
           cout<<dwServiceType<<endl;//输出3.
           cout<<nPort<<endl;                  //输出80. 
           MessageBox(NULL,strServer,"待解析的URL服务器名",MB_OK);                              //    image.baidu.com
           MessageBox(NULL,strObject,"待解析的URL 涉及的对象(可能为空)",MB_OK); //    /donghua.gif
           return 0;
}

实例分析:url这个参数,我们可以随便赋值,只是影响AfxParseURL的解析结果,当然我们下载的时候都是从某个网址下载。

                    dwServiceType这个参数说明了服务的类型。从下面可以看出3代表http(系统定义的)。

#define INTERNET_SERVICE_URL    0
#define INTERNET_SERVICE_FTP    1
#define INTERNET_SERVICE_GOPHER 2
#define INTERNET_SERVICE_HTTP   3

    nPort:80代表http服务的端口号。

第二步:下次分析。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值