Files
ProgressQuest/Web.pas
T
Eric Fredricksen 5e7e820533 [contents of README]
ProgressQuest v6.2 (probably as released)
-----------------------------------------
This directory represents an ex post facto rendering of pq6 in its
various versions in svn, so that changes will be trackable thataway.

The version as of this moment in svn is 6.2 (but I had two copies
around, so I'm not positive this is the final one, and not the prev
rev checked in)

(I didn't add this file in PQ 6.0, but after that you can use this README
to trace the checkin history using svn.)
2006-12-24 21:04:57 +00:00

88 lines
2.8 KiB
ObjectPascal

unit Web;
interface
uses
Windows, Messages, SysUtils, Classes, WinInet;
type
EWebError = class(Exception);
function DownloadString(url: String): String;
var
// Change to false to insist on no proxy
ProxyOK: Boolean;
implementation
{
function OpenAuthUrl(net: HInternet; url, username, password: String): HInternet;
var
connection: HInternet;
begin
connection := InternetConnect(net, host, port, nil, nil,
INTERNET_SERVICE_HTTP, 0, 0);
Result := HttpOpenRequest(Connection, "GET", path,
nil, nil, nil,
// INTERNET_FLAG_KEEP_CONNECTION or
INTERNET_FLAG_RELOAD or
INTERNET_FLAG_PRAGMA_NOCACHE or
INTERNET_FLAG_NO_UI, 0);
InternetSetOption(result, INTERNET_OPTION_USERNAME,
PChar(username), len(username));
InternetSetOption(result, INTERNET_OPTION_PASSWORD,
PChar(password), len(password));
HttpSendRequest(result, nil, 0, nil, 0);
//HttpQueryInfo(Resource, HTTP_QUERY_FLAG_NUMBER |
// HTTP_QUERY_STATUS_CODE, &dwStatus, &dwStatusSize, NULL);
end;
}
function DownloadString(url: string): string;
var
NetHandle: HINTERNET;
UrlHandle: HINTERNET;
Buffer: array[0..1024] of Char;
BytesRead: dWord;
conntype: DWORD;
begin
Result := '';
conntype := INTERNET_OPEN_TYPE_DIRECT;
if proxyok then conntype := INTERNET_OPEN_TYPE_PRECONFIG;
NetHandle := InternetOpen('PQ6.2', conntype, nil, nil, 0);
if Assigned(NetHandle) then
begin {
if Len(username + password) > 0 then
UrlHandle := OpenAuthUrl(NetHandle, username, password)
else }
UrlHandle := InternetOpenUrl(NetHandle, PChar(Url),
nil, 0, // headers[size]
INTERNET_FLAG_KEEP_CONNECTION or
INTERNET_FLAG_RELOAD or
INTERNET_FLAG_PRAGMA_NOCACHE or
INTERNET_FLAG_NO_UI,
0);
if Assigned(UrlHandle) then begin
repeat
InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer)-1, BytesRead);
Buffer[BytesRead] := #0;
Result := Result + Buffer;
until BytesRead = 0;
InternetCloseHandle(UrlHandle);
end else begin
raise EWebError.CreateFmt('Cannot open URL %s', [Url]);
end;
InternetCloseHandle(NetHandle);
end else begin
// NetHandle is not valid. Raise an exception
raise EWebError.Create('Unable to initialize internet API');
end;
end;
initialization
ProxyOK := True;
end.