.


:




:

































 

 

 

 


Internet

16

INTERNET

: WinInet Internet.

 

1.

 

.

WinInet.

WinInet.

 

1.1. WinInet

 

WinInet internet - HTTP, FTP Gopher.

Web- .

1) ( IntetnetOpen).

2) URE ( InternetOpenUrl).

3) html- ( InternetReadFile).

4) ( InternetCloseHandle).

FTP- .

1) ( IntetnetOpen).

2) FTP- ( IntetnetConnect).

3) FTP - ( FtpFindFirstFile FtpFindNextFile - FTP - FtpGetCurrentDirectory FtpGetFile - , FTP - . .).

4) ( InternetCloseHandle).

 

1.2. WININET

 

1.2.1. InternetOpen

 

function InternetOpen(

lpszAgent: PChar;

dwAccessType: DWORD;

IpszProxy, IpszProxyBypass: PChar;

dwFlags: DWORD): HINTERNET: stdcall;

lpszAgenl - , . nil, ;

dwAccessType - . . 1;

1

FTP-

 

INTERNET OPEN DIRECT
INTERNET OPEN PRECONFIG pe

 

IpszProxyName - , proxy-. nil;

IpszProxyBypass - proxy-. nil;

dwFlags - . : INTERNET_FLAG_ASYNC,INTERNET_FLAG_FROM_CACHE: INTERNET_FLAG_OFFLINE.

. nil.

 

1.2.2. URL- InternetOpenUrl

 

function lnlernetOpenUrl(

hinet: HINTERNET;

IpszUrl: PChar;

Ipszl leaders: PChar;

dwHeadersLeugth: DWORD:

dwFlags: DWORD;

dwContext: DWORD): HINTERNET; stdcall;,

hInternet - , InternetOpen;

IpszUrl URL;

IpszHeaders - , , HTTP -;

dwFIeadersLengih - , nil;

dwFlags- ;

dwContext - 0.

: . nil.

 

1.2.3. , WEB-cepepe InternetReadFile

 

function IniernetReadFile(

hFile: HINTERNET; IpBuffer: Pointer;

dwNumberOfBytesToRead: DWORD;

varlpdvvNumberOfBytesRead: DWORD): BOOL; stdcall;

hFile - , InternetOpenUrl, FtpOpenFile HttpOpenRequest;

IpBuffer - ,

dwNumberOfBytesToRead - ;

lpdwNumberOfBytesRead - . - TRUE FALSE .

 

1.2.4. InternetCloscHandle

 

function InlernelCloseHandle(hInet: HINTERNET): BOOL; stdcall;,

hInternet - Internet.

TRUE FALSE .

 

1.2.5. InternetConnect

 

function InternetConnect(

hInet: HINTERNET;

IpszServerName: PChar;

nServerPort: INTERNET PORT;

IpszUsername: PChar;

IpszPassword: PChar;

dwService: DWORD;

dwFlags: DWORD;

dwContext: DWORD): HINTERNET; stdcall;

hInternet - , Internet Open;

IpszServerName - , . Internet;

nServerPort - . , , . 2;

IpszUsername - , , ;

IpszPassword - , , ;

dwService . :

INTERNET_SERVICE_FTP FTP-,

INTERNET_SERVICE_GOPHER Gopher-,

INTERNET_SERVICE_HTTP TP-;

dwFlags - . :

INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE;

dwContext- 0,

FTP-, Gopher- HTTP-, nil .

 

2

,

INTERNET_DEFAULT_FTP_PORT FTP -(21)
INTERNET_DEFAULT_GOPHER_PORT   Gopher- (70)
INTERNET_DEFAULT_HTTP_PORT HTTP- (80)
INTERNET_DEFAULT_HTTPS_PORT   S (443)
INTERNET_DEFAULT_SOCKS_PORT   SOCKS firewall- (1080)  

 

1.2.6. FtpFindFirstFile

 

function FtpFindFirstFile(

hConnect: HINTERNET;

IpszSearchFile: PChar;

var IpFindFileData:

TWin32FindData;

dwFlags: DWORD;

dwContext: DWORD): HINTERNET; stdcall;

hConnect - , InternelConnect;

IpszSearchFile - , , ;

IpFindFileData - WIN32_ FIND DATA, . ;

dwFlags- ;

dwContext - 0. : nil. .

 

1.2.7. InternetFindNextFile

 

function InternetFindNextFile (

hFind: HINTERNET;

IpvFindData: Pointer). BOOL; stdcall;

hFind - , FtpFindFirstFile GopherFindFirstFile, InternetOpenUrl ( );

IpvFindData - WIN32_FIND_DATA, . .

: TRUE FALSE .

 

1.2.8. ftp- -FtpGetCurrentDirectory

 

function FtpGetCuircutDirectory(

hConnect: HINTERNET:

IpszCurrentDireetory: PChar;

var IpdwCurrenlDirectory: DWORD): BOOL; stdcall;,

hConnect - FTP- ( InternetConnect);

IpszCurrentDireclory - , , ;

IpdwCurrentDirectory - . TRUE FALSE .

. IpszCurrentDireclory , IpdwCurrentDirectory .

 

1.2.9. HTTP- FtpGetFile

 

function FtpGetFile(

hConnect: HINTERNET;

IpszReinoteFile: PChar;

IpszNewFile: PChar;

fFaillfExists:BOOL:

dwFlagsAndAttributes: DWORD;

dwFlags: DWORD; dwContext: DWORD): BOOL, stdcall;,

hConnect - ( InternetConnect);

IpszRemoteFile - , , ;

IpszNewFile - , , , F-;

fFaillfExists - , , . fFaillfExists TRUE, FtpGetFile ;

dwFiagsAndAttribtites - . FILE_ATTRIBUTE_*, CreateFile;

dwFlags - . ;

INTERNET_FLAG_TRANSFER_ASCII - ASCII,

INTERNET_ FLAG_TRANSFER _BINARY - ;

dwContext - 0. TRUE FALSE .

 

2.

 

2.1. .

 

, , . 1.

 

. 1

 

, .3.

 

3

Label1 TLabel URL Web-
Label2 TLabel F-
Label3 TLabel Web-
Label4 TLabel FTP-
Label5 TLabel
Label6 TLabel
Label7 TLabel
Memo1 TMemo Web-
Memo2 TMemo FTP-
Edi1 TEdi 1 URL Web-
Edi2 TEdi 1 FTP-
Edi3 TEdi 1 ( FTP-)
Edi4 TEdi 1 ( , , FTP-)
Edi5 TEdi 1 FTP-
Button1 TButton Web-
Button2 TButton -
Button3 TButton FTP-
Button4 TButton FTP-
Button5 TButton FTP-
Button6 TButton
Button7 TButton

 

:

1) WinInet ( - uses):

 

uses

Windows, Messages, SysUtils, Variants, Classes. Graphics, Controls, Forms,

Dialogs, StdCtrls. WinInet;

 

2) :

Var

Form 1: TForm l;

hsession, hconnect, hfile: hInternet;

3) OnCreale Form1 :

 

Memo1.Clear;

Memo2.Clear;

// , Web-

Edit 1.Text:= 'http://myself/www/index.html';

// FTP-

Edit2.Text:='127.0.0.1';

// , FTP- ,

Edit 3.Text:= 'fttp 1/Index.html';

// , ,

// FTP-

Edit 4.Text:= 'C:\file.txt';

// ' FTP-, m2 Edit5.Text:= '/ftp1/*.*';

 

4) OnClick WEB-e :

 

procedure TForm1.Button1 Click(Sender: TObject);

VAR

url: Siring:

buf: Array[1..100] of char;

dwtotal: dword;

s: String;

k: Integer;

begin

url:= Editl.Text;

If Pos(http://', Lowercase(url))=0 then (url):= 'http://'+url;

//

hSession:= InternetOpen(nil,

INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);

If Assigned(hSession) then

begin

// URL

file:=intenetOpenUrlhSession, PChar(url),

nil, 0, INTERNET_FLAG_RELOAD, 0);

If Assigned(hfile) then

begin

// html-

internetReadFile(hfile, @buf, sizeof(buf), dwtotal);

s:= String(buf);

memo 1.Lines.Add(s);

//

InternetCloseHandle(hfile):

end:

//

InternetCloseHandle(hsession);

end;

end:

 

5) OnClick c FTP - :

 

procedure TForm1.Button2CTick(Sender: TObject);

VAR

url: String:

srvname: Array [1..100] of char;

begin

url:= Edit2.Text;

StrPCopy(@srvname,url);

//

hSession:= IntemetOpen(nil, INTERNET_OPBN_TYPE_PRECONFIG

nil, nil. 0);

If Assigned(hSession) then

begin

// - anonymous

//

connect:= InternetConnect(hSession, @srvname, 21,

'anonymous', nil, INTERNET_SERVICE_FTP, 0, 0);

IF Assigned (connect) then

ShowMessage(' FTP- ');

end;

end;

 

6) OnCIick :

 

procedure TForm1.Buttun5Click(Sender: TObject);

VAR

DirInfo: W1N32_FIND_ DATA;

hDir: hInternet;

DirList: Array [1.. 100] of char;

dwflag: DWORD;

result: Boolean;

begin

StrPCopy(@DirLis1. Edit5.Text);

//

hDir:= FtpFindFirstFile(hConnect, @DirList, DirInfo, dwFlag, 0);

//

if not Assigned(hdir) then

begin

if GetLastError()=ERROR_NO_MORE_FILES then

begin

ShovvMessage('B ');

InternetCloseHandle(hDir);

end

else

begin

ShowMessageFmt(' %d', [GetLastError ()]);

IntemetCloseHandle(hDir):

end;

end

else

begin

// Memo2

memo2. Lines. Add(DirInfo.cFileName):

ifDirInfo.dwFileAttribules=FILE_ATTRIBUTE_DIRECTORY

then memo2.Lines.Add(DirInfo.cFileName+'<DlR>')

else memo2.Lines. Add(DirInfo.cFileName);

//

repeat

result:= InternetFindNextFile (hDir, @DirInfo);

if not result then

if GetLastERROR()=ERROR_NO_MORE_FILES

Then InternetCloseHandle(hDir)

else

begin

ShowMessageFmt(' %d', [GetLastError ()]);

InternetCloseHandle(hDir);

end

else

begin

ifDirInfo.dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY

then memo2.Lines.Add(DirInfo.cFiIeName+'<DIR>')

else memo2.Lines.Add(DirInfo.cFileName);

end;

until not result;

end;

end;.

 

 

1. OnClick , FtpGelCurrentDirectory.

2. OnClick , FtpGelFile.

3. Web- buf. Web-. html- </HTML>.

 

 

1. . Visual ++6. /. . ., , 1999. 864 .

2. . A. Delphi. . ., -, 2004.976 .

3. ., . INTERNET Windows /. . ., , 1996. 688 .

 

 

1. FTP.

2. HTTP.

3. FTP.

4. HTTP.

5. FTP.EXE.

6. URL?


17



<== | ==>
| TFTP
:


: 2018-11-11; !; : 169 |


:

:

, , .
==> ...

1856 - | 1498 -


© 2015-2024 lektsii.org - -

: 0.094 .