Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.03.27;
Скачать: CL | DM;

Вниз

как создать подлючение к интернету через прокси   Найти похожие ветки 

 
Zloy ©   (2005-01-24 16:06) [0]

вот откопал я такой код, для подключения, и так получается подключаться на прямую, когда без прокси, но хочется предусмотреть подключению через прокси, не подскажите где править
Uses WinInet;
function FtpDownloadFile(strHost, strUser, strPwd: string;
 Port: Integer; ftpDir, ftpFile, TargetFile: string; ProgressBar: TProgressBar): Boolean;
  function FmtFileSize(Size: Integer): string;

 const
 READ_BUFFERSIZE = 4096;  // or 256, 512, ...
var
 hNet, hFTP, hFile: HINTERNET;
 buffer: array[0..READ_BUFFERSIZE - 1] of Char;
 bufsize, dwBytesRead, fileSize: DWORD;
 sRec: TWin32FindData;
 strStatus: string;
 LocalFile: file;
 bSuccess: Boolean;
 str: string;
implementation

  function FmtFileSize(Size: Integer): string;
 begin
   if Size >= $F4240 then
     Result := Format("%.2f", [Size / $F4240]) + " Mb"
   else
   if Size < 1000 then
     Result := IntToStr(Size) + " bytes"
   else
     Result := Format("%.2f", [Size / 1000]) + " Kb";
 end;

function FtpDownloadFile(strHost, strUser, strPwd: string;
 Port: Integer; ftpDir, ftpFile, TargetFile: string; ProgressBar: TProgressBar): Boolean;

begin
 Result := False;

 { Open an internet session }
 hNet := InternetOpen("Program_Name", // Agent
                       INTERNET_OPEN_TYPE_PRECONFIG, // AccessType
                       nil,  // ProxyName
                       nil, // ProxyBypass
                       0); // or INTERNET_FLAG_ASYNC / INTERNET_FLAG_OFFLINE

 {
   Agent contains the name of the application or
   entity calling the Internet functions
 }

 { See if connection handle is valid }
 if hNet = nil then
 begin
   ShowMessage("&#207;&#240;&#238;&#225;&#235;&#229;&#236;&#251; &#241; WinInet.Dll");
   Exit;

 end;

 { Connect to the FTP Server }
 hFTP := InternetConnect(hNet, // Handle from InternetOpen
                         PChar(strHost), // FTP server
                         port, // (INTERNET_DEFAULT_FTP_PORT),
                         PChar(StrUser), // username
                         PChar(strPwd),  // password
                         INTERNET_SERVICE_FTP, // FTP, HTTP, or Gopher?
                         0, // flag: 0 or INTERNET_FLAG_PASSIVE
                         0);// User defined number for callback

 if hFTP = nil then
 begin
   InternetCloseHandle(hNet);
  ShowMessage(Format("&#209;&#229;&#240;&#226;&#229;&#240; "%s" &#237;&#229; &#237;&#224;&#233;&#228;&#229;&#237;, &#239;&#240;&#238;&#226;&#229;&#240;&#252;&#242;&#229; &#239;&#238;&#228;&#234;&#235;&#254;&#247;&#229;&#237;&#232;&#229; &#234; &#232;&#237;&#242;&#229;&#240;&#237;&#229;&#242;&#243;",[strHost]));
  Exit;

 end;

 { Change directory }
 bSuccess := FtpSetCurrentDirectory(hFTP, PChar(ftpDir));

 if not bSuccess then
 begin
   InternetCloseHandle(hFTP);
   InternetCloseHandle(hNet);
   ShowMessage(Format("&#194;&#240;&#229;&#236;&#229;&#237;&#237;&#251;&#233; &#239;&#240;&#238;&#225;&#235;&#229;&#236;&#251; &#241; &#241;&#229;&#240;&#226;&#229;&#240;&#238;&#236;, &#239;&#238;&#228;&#234;&#235;&#254;&#247;&#232;&#242;&#229;&#241;&#252; &#239;&#238;&#231;&#230;&#229; %s.",[ftpDir]));
   Exit;
 end;

 { Read size of file }
 if FtpFindFirstFile(hFTP, PChar(ftpFile), sRec, 0, 0) <> nil then
 begin

   fileSize := sRec.nFileSizeLow;
   // fileLastWritetime := sRec.lastWriteTime
 end else
 begin
   InternetCloseHandle(hFTP);
   InternetCloseHandle(hNet);
   ShowMessage(Format("Cannot find file ",[ftpFile]));
   Exit;
 end;

 { Open the file }
 hFile := FtpOpenFile(hFTP, // Handle to the ftp session
                      PChar(ftpFile), // filename
                      GENERIC_READ, // dwAccess
                      FTP_TRANSFER_TYPE_BINARY, // dwFlags
                      0); // This is the context used for callbacks.

 if hFile = nil then
 begin
   InternetCloseHandle(hFTP);
   InternetCloseHandle(hNet);
   Exit;
 end;

 { Create a new local file }
 str:= TargetFile;
 AssignFile(LocalFile, TargetFile);
 {$i-}
 Rewrite(LocalFile, 1);
 {$i+}

 if IOResult <> 0 then
 begin
   InternetCloseHandle(hFile);
   InternetCloseHandle(hFTP);
   InternetCloseHandle(hNet);
   Exit;
 end;

 dwBytesRead := 0;
 bufsize := READ_BUFFERSIZE;

 while (bufsize > 0) do
 begin
   Application.ProcessMessages;

   if not InternetReadFile(hFile,
                           @buffer, // address of a buffer that receives the data
                           READ_BUFFERSIZE, // number of bytes to read from the file
                           bufsize) then Break; // receives the actual number of bytes read

   if (bufsize > 0) and (bufsize <= READ_BUFFERSIZE) then
    Form9.Show;
     BlockWrite(LocalFile, buffer, bufsize);
   dwBytesRead := dwBytesRead + bufsize;

   { Show Progress }

   ProgressBar.Position := Round(dwBytesRead * 100 / fileSize);
  Form9.Label1.Caption := Format("%s of %s / %d %%",[FmtFileSize(dwBytesRead),FmtFileSize(fileSize) ,ProgressBar.Position]);

 end;

 CloseFile(LocalFile);

 InternetCloseHandle(hFile);
 InternetCloseHandle(hFTP);
 InternetCloseHandle(hNet);
 Result := True;
Form9.Close;
end;


 
Zloy ©   (2005-01-24 17:43) [1]

up


 
Zloy ©   (2005-01-28 10:12) [2]

ну не уж то ни кто не знает.....


 
hooch ©   (2005-01-28 10:33) [3]

если указана константа INTERNET_OPEN_TYPE_PRECONFIG то данные для соединения беруться из реестра, в том числе и настройка прокси, тут почитай http://www.delphiworld.narod.ru/


 
Zloy ©   (2005-01-28 11:20) [4]

собственно я оттуда и скачал этот код, я пытаюсь использовать
INTERNET_OPEN_TYPE_PROXY(
"192.168.0.1:3128",  // ProxyName
                      nil, // ProxyBypass
                      0); // or INTERNET_FLAG_ASYNC / )INTERNET_FLAG_OFFLINE

и все равно он не хочет конектиться через прокси


 
dDan   (2005-01-28 18:11) [5]

Еще возник вопрос: если прокся требует авторизацию как ее произвести



Страницы: 1 вся ветка

Текущий архив: 2005.03.27;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.11 c
14-1109935545
boriskb
2005-03-04 14:25
2005.03.27
Молдавия


4-1107982050
Massiv
2005-02-09 23:47
2005.03.27
Чтение LocalMachine KEY


1-1110969733
Прогин
2005-03-16 13:42
2005.03.27
XML Mapping


14-1110398834
Суслик
2005-03-09 23:07
2005.03.27
Это не про дельфи 2005, а про дельфи 6.


1-1110974246
Vetal
2005-03-16 14:57
2005.03.27
Посоветуйте плиз Grid (не DB)