Jump to content

Internet


cibersoft

Recommended Posts

Dependendo da versão do Delphi que possuis, e dos componentes que tens à tua disposição, podes usar um componente de cliente de http e/ou ftp para isso. Consulta a documentação e vê os tutoriais que acompanham o Delphi.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Há imensos componentes VCL por ai, "google it". 🙂

De certo vais encontrar alguns que até já fazem o que pretendes. No limite podes sempre usar o OCX do IE embebido numa aplicação tua.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Aqui está um exemplo:

uses WinInet;

function GetInetFile (const fileURL, FileName: String): boolean;
const
  BufferSize = 1024;
var
  hSession, hURL: HInternet;
  Buffer: array[1..BufferSize] of Byte;
  BufferLen: DWORD;
  f: File;
  sAppName: string;
begin
  Result:=False;
  sAppName := ExtractFileName(Application.ExeName);
  hSession := InternetOpen(PChar(sAppName),
                           INTERNET_OPEN_TYPE_PRECONFIG,
                           nil, nil, 0);
  try
    hURL := InternetOpenURL(hSession,
            PChar(fileURL),
            nil,0,0,0);
    try
      AssignFile(f, FileName);
      Rewrite(f,1);
      repeat
        InternetReadFile(hURL, @Buffer,
                         SizeOf(Buffer), BufferLen);
        BlockWrite(f, Buffer, BufferLen)
      until BufferLen = 0;
      CloseFile(f);
      Result:=True;
    finally
     InternetCloseHandle(hURL)
    end
  finally
    InternetCloseHandle(hSession)
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  InternetFile,LocalFile: string;
begin
  InternetFile:='http://www.delphitips.com/images/delphispirit.gif';
  LocalFile:='c:/delphispirit.gif';

  if GetInetFile(InternetFile,LocalFile)=True then
     ShowMessage('download')
  else
    ShowMessage('Can not download the updated files');
end;
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.