AfxParseURL如何解析URL
时间: 2024-04-28 20:20:55 浏览: 16
AfxParseURL是MFC中的一个函数,用于解析URL字符串。它的用法如下:
```c++
BOOL AfxParseURL(LPCTSTR lpszURL, DWORD& dwServiceType, CString& strServer, CString& strObject, INTERNET_PORT& nPort);
```
其中:
- lpszURL:需要解析的URL字符串。
- dwServiceType:解析后的协议类型,如FTP、HTTP、HTTPS等。
- strServer:解析后的服务器名。
- strObject:解析后的对象路径。
- nPort:解析后的端口号。
示例代码如下:
```c++
CString strURL = _T("http://www.baidu.com/index.html");
DWORD dwServiceType = 0;
CString strServer;
CString strObject;
INTERNET_PORT nPort = 0;
BOOL bParse = AfxParseURL(strURL, dwServiceType, strServer, strObject, nPort);
if (bParse)
{
// 解析成功
// dwServiceType为INTERNET_SERVICE_HTTP
// strServer为"www.baidu.com"
// strObject为"/index.html"
// nPort为80
}
else
{
// 解析失败
}
```
注意,AfxParseURL只能解析标准格式的URL字符串,如`http://www.baidu.com/index.html`,不能解析不标准的URL字符串,如`www.baidu.com/index.html`。