Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取winapi中的URL部分_Url_Winapi - Fatal编程技术网

获取winapi中的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 \___________/ \___/ \________/ \____________________/ \___/ \_____________________

Windows中是否有API可以将url分解为多个部分

背景 URL的格式为:

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
  • 片段
    鼻子
有些函数不起作用 WinApi中有一些函数,但它们无法完成任务,因为它们不了解方案,除了
WinHttp
可以使用的方案外:

  • (禁止http或https以外的任何方案)
两者都无法理解URL,例如:

  • ws://stackoverflow.com
    (web套接字)
  • wss://stackoverflow.com
    (web套接字安全)
  • sftp://fincen.gov/submit
    (SSL文件传输)
  • 磁铁:?xt=urn:btih:c4244b6d0901f71add9a1f9e88013a2fa51a9900
  • 地层+udp://blockchain.info
WinHttpCrackUrl主动防止被用于破解URL:

如果为pwszUrl传入的URL的Internet协议不是HTTP或HTTPS,则WinHttpCrackUrl返回FALSEGetLastError表示

Windows中是否有其他本机API可以获取url的一部分

花言巧语 以下是您在CLR中的操作方法(例如C#):()

输出

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的客户端版本)
其中,InternetCrackUrl起作用

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
将ExtraInfo解析为查询和片段 InternetCrackUrl没有区分以下内容,真是糟糕透了:

?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
    • 片段
      #鼻子

本机Windows开发人员可以使用许多功能:

  • :Shell轻量级实用程序函数
  • :WinHTTP 5.1
  • :WinINet(WinHTTP的客户端版本)
其中,InternetCrackUrl起作用

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
将ExtraInfo解析为查询和片段 InternetCrackUrl没有区分以下内容,真是糟糕透了:

?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
    • 片段
      #鼻子
有没有