1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| {$APPTYPE CONSOLE} uses Windows, SysUtils, WinInet; procedure ParseURL(const lpszUrl: string); var lpszScheme : array[0..INTERNET_MAX_SCHEME_LENGTH - 1] of Char; lpszHostName : array[0..INTERNET_MAX_HOST_NAME_LENGTH - 1] of Char; lpszUserName : array[0..INTERNET_MAX_USER_NAME_LENGTH - 1] of Char; lpszPassword : array[0..INTERNET_MAX_PASSWORD_LENGTH - 1] of Char; lpszUrlPath : array[0..INTERNET_MAX_PATH_LENGTH - 1] of Char; lpszExtraInfo : array[0..1024 - 1] of Char; lpUrlComponents : TURLComponents; begin ZeroMemory(@lpszScheme, SizeOf(lpszScheme)); ZeroMemory(@lpszHostName, SizeOf(lpszHostName)); ZeroMemory(@lpszUserName, SizeOf(lpszUserName)); ZeroMemory(@lpszPassword, SizeOf(lpszPassword)); ZeroMemory(@lpszUrlPath, SizeOf(lpszUrlPath)); ZeroMemory(@lpszExtraInfo, SizeOf(lpszExtraInfo)); ZeroMemory(@lpUrlComponents, SizeOf(TURLComponents)); lpUrlComponents.dwStructSize := SizeOf(TURLComponents); lpUrlComponents.lpszScheme := lpszScheme; lpUrlComponents.dwSchemeLength := SizeOf(lpszScheme); lpUrlComponents.lpszHostName := lpszHostName; lpUrlComponents.dwHostNameLength := SizeOf(lpszHostName); lpUrlComponents.lpszUserName := lpszUserName; lpUrlComponents.dwUserNameLength := SizeOf(lpszUserName); lpUrlComponents.lpszPassword := lpszPassword; lpUrlComponents.dwPasswordLength := SizeOf(lpszPassword); lpUrlComponents.lpszUrlPath := lpszUrlPath; lpUrlComponents.dwUrlPathLength := SizeOf(lpszUrlPath); lpUrlComponents.lpszExtraInfo := lpszExtraInfo; lpUrlComponents.dwExtraInfoLength := SizeOf(lpszExtraInfo); InternetCrackUrl(PChar(lpszUrl), Length(lpszUrl), ICU_DECODE or ICU_ESCAPE, lpUrlComponents); Writeln(Format('Protocol : %s',[lpszScheme])); Writeln(Format('Host : %s',[lpszHostName])); Writeln(Format('User : %s',[lpszUserName])); Writeln(Format('Password : %s',[lpszPassword])); Writeln(Format('Path : %s',[lpszUrlPath])); Writeln(Format('ExtraInfo: %s',[lpszExtraInfo])); end; begin try ParseURL('http://login:password@somehost.somedomain.com/some_path/something_else.html?param1=val¶m2=val'); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; readln; end.
|