获取winapi中的URL部分
Windows中是否有API可以将url分解为多个部分 背景 URL的格式为:获取winapi中的URL部分,url,winapi,Url,Winapi,Windows中是否有API可以将url分解为多个部分 背景 URL的格式为: stackoverflow://iboyd:password01@mail.stackoverflow.com:12386/questions/SubmitQuestion.aspx?useLiveData=1&internal=0#nose \___________/ \___/ \________/ \____________________/ \___/ \_____________________
stackoverflow://iboyd:password01@mail.stackoverflow.com:12386/questions/SubmitQuestion.aspx?useLiveData=1&internal=0#nose
\___________/ \___/ \________/ \____________________/ \___/ \___________________________/\_______________________/ \__/
| | | | | | | |
scheme username password hostname port path query fragment
(本机)Win32 api中是否有一个函数可以将URL分解为多个部分:
- 方案:
堆栈溢出
- 用户名:
iboyd
- 密码:
password01
- 主机名:
mail.stackoverflow.com
- 端口:
12386
- 路径:
问题/SubmitQuestion.aspx
- 查询:
?使用livedata=1&internal=0
- 片段:
鼻子
WinHttp
可以使用的方案外:
- (禁止http或https以外的任何方案)
(web套接字)ws://stackoverflow.com
(web套接字安全)wss://stackoverflow.com
(SSL文件传输)sftp://fincen.gov/submit
磁铁:?xt=urn:btih:c4244b6d0901f71add9a1f9e88013a2fa51a9900
地层+udp://blockchain.info
Uri.Scheme: stackoverflow
Uri.UserInfo: iboyd:password01
Uri.Host: mail.stackoverflow.com
Uri.Port: 12386
Uri.AbsolutePath: /questions/SubmitQuestion.aspx
Uri.Query: ?useLiveData=1&internal=0
Uri.Fragment: #nose
本机Windows开发人员可以使用许多功能:
- :Shell轻量级实用程序函数
- :WinHTTP 5.1
- :WinINet(WinHTTP的客户端版本)
URL_COMPONENTS components;
components.dwStructSize = sizeof(URL_COMPONENTS);
components.dwSchemeLength = DWORD(-1);
components.dwHostNameLength = DWORD(-1);
components.dwUserNameLength = DWORD(-1);
components.dwPasswordLength = DWORD(-1);
components.dwUrlPathLength = DWORD(-1);
components.dwExtraInfoLength = DWORD(-1);
if (!InternetCrackUrl(url, url.Length, 0, ref components)
RaiseLastOSError();
String scheme = StrLCopy(components.lpszScheme, components.dwSchemeLength);
String username = StrLCopy(components.lpszUserName, components.dwUserNameLength);
String password = StrLCopy(components.lpszPassword, components.dwPasswordLength);
String host = StrLCopy(components.lpszHostName, components.dwHostNameLength);
Int32 port = components.nPort;
String path = StrLCopy(components.lpszUrlPath, components.dwUrlPathLength);
String extra = StrLCopy(components.lpszExtraInfo, components.dwExtraInfoLength);
这意味着
斯塔克koverflow://iboyd:password01@mail.stackoverflow.com:12386/questions/SubmitQuestion.aspx?useLiveData=1&internal=0#
被解析为:
- 方案:
堆栈溢出
- 用户名:
iboyd
- 密码:
password01
- 主机:
mail.stackoverflow.com
- 端口:
12386
- 路径:
/questions/SubmitQuestion.aspx
- 外部信息:
?使用livedata=1&internal=0#nose
?query#fragment
然后将它们混合在一起作为ExtraInfo:
- 外部信息:
?使用livedata=1&internal=0#nose
- 查询:
?使用livedata=1&internal=0
- 片段:
#鼻子
- 查询:
?查询
或#片段
,我们必须进行一些拆分:
/*
InternetCrackUrl returns ?query#fragment in a single combined extraInfo field.
Split that into separate
?query
#fragment
*/
String query = extraInfo;
String fragment = "";
Int32 n = StrPos("#", extraInfo);
if (n >= 1) //one-based string indexes
{
query = extraInfo.SubString(1, n-1);
fragment = extraInfo.SubString(n, MaxInt);
}
为我们提供所需的最终结果:
- 方案:
堆栈溢出
- 用户名:
iboyd
- 密码:
password01
- 主机:
mail.stackoverflow.com
- 端口:
12386
- 路径:
/questions/SubmitQuestion.aspx
- 外部信息:
?使用livedata=1&internal=0#nose
- 查询:
?使用livedata=1&internal=0
- 片段:
#鼻子
- 查询:
- :Shell轻量级实用程序函数
- :WinHTTP 5.1
- :WinINet(WinHTTP的客户端版本)
URL_COMPONENTS components;
components.dwStructSize = sizeof(URL_COMPONENTS);
components.dwSchemeLength = DWORD(-1);
components.dwHostNameLength = DWORD(-1);
components.dwUserNameLength = DWORD(-1);
components.dwPasswordLength = DWORD(-1);
components.dwUrlPathLength = DWORD(-1);
components.dwExtraInfoLength = DWORD(-1);
if (!InternetCrackUrl(url, url.Length, 0, ref components)
RaiseLastOSError();
String scheme = StrLCopy(components.lpszScheme, components.dwSchemeLength);
String username = StrLCopy(components.lpszUserName, components.dwUserNameLength);
String password = StrLCopy(components.lpszPassword, components.dwPasswordLength);
String host = StrLCopy(components.lpszHostName, components.dwHostNameLength);
Int32 port = components.nPort;
String path = StrLCopy(components.lpszUrlPath, components.dwUrlPathLength);
String extra = StrLCopy(components.lpszExtraInfo, components.dwExtraInfoLength);
这意味着
斯塔克koverflow://iboyd:password01@mail.stackoverflow.com:12386/questions/SubmitQuestion.aspx?useLiveData=1&internal=0#
被解析为:
- 方案:
堆栈溢出
- 用户名:
iboyd
- 密码:
password01
- 主机:
mail.stackoverflow.com
- 端口:
12386
- 路径:
/questions/SubmitQuestion.aspx
- 外部信息:
?使用livedata=1&internal=0#nose
?query#fragment
然后将它们混合在一起作为ExtraInfo:
- 外部信息:
?使用livedata=1&internal=0#nose
- 查询:
?使用livedata=1&internal=0
- 片段:
#鼻子
- 查询:
?查询
或#片段
,我们必须进行一些拆分:
/*
InternetCrackUrl returns ?query#fragment in a single combined extraInfo field.
Split that into separate
?query
#fragment
*/
String query = extraInfo;
String fragment = "";
Int32 n = StrPos("#", extraInfo);
if (n >= 1) //one-based string indexes
{
query = extraInfo.SubString(1, n-1);
fragment = extraInfo.SubString(n, MaxInt);
}
为我们提供所需的最终结果:
- 方案:
堆栈溢出
- 用户名:
iboyd
- 密码:
password01
- 主机:
mail.stackoverflow.com
- 端口:
12386
- 路径:
/questions/SubmitQuestion.aspx
- 外部信息:
?使用livedata=1&internal=0#nose
- 查询:
?使用livedata=1&internal=0
- 片段:
#鼻子
- 查询: