wininet的httpGet能把URL上的主页内容Get下来: unit ReadHttpFiles;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, wininet, StdCtrls, ComCtrls;type TForm1 = class(TForm) Button1: TButton; RichEdit1: TRichEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject); var hIs, hIc, hIR : Hinternet; pcbuf : pChar; dwRead : Dword; begin dwRead := 0; GetMem(pcbuf,1024); hIs := InternetOpen('HttpGet', INTERNET_OPEN_TYPE_DIRECT, NIL, NIL,0); hIc := InternetConnect(hIs, 'www.microsoft.com', INTERNET_DEFAULT_HTTP_PORT, NIL, NIL, INTERNET_SERVICE_HTTP,0,0); hIR := HttpOpenRequest(hIC, nil, '/Default.asp', nil, nil,nil, 0,0); if HttpSendRequest(hIR, nil, 0,nil,0) then begin while InternetReadFile(hIR, pcbuf,1024,dwRead) do begin if dwRead <= 0 then break; RichEdit1.Text := RichEdit1.text + pcBuf; end; end; InternetCloseHandle(hIR); InternetCloseHandle(hIC); InternetCloseHandle(hIs); FreeMem(pcBuf); end;end. 需要把上面例子的"www.microsoft.com"改为你上拿的网站, "/default.asp" 改为你要的html文件.
There are a number of ways to do this, below is a simple code snippit that will give you an idea of how to do this. Make sure to add ShellApi, and UrlMon to your uses clause. function DownLoadInternetFile(Source, Dest : String): Boolean; begin try Result := URLDownloadToFile(nil,PChar(Source),PChar(Dest),0,nil) = 0 except Result := False; end; end;procedure TForm1.Button1Click(Sender: TObject); var SourceString, DestinationString: string; begin //File location on the Internet. SourceString := 'http://www.borland.com/images/homepage/del6homemural.gif'; //File destination. DestinationString := 'C:Tempdel6homemural.gif'; if DownLoadInternetFile(SourceString, DestinationString) then //This will display the file from your browser. ShellExecute(Application.Handle, PChar('Open'), PChar(DestinationString), PChar(''), nil, SW_NORMAL) else ShowMessage('Error during Download ' + SourceString); end;
在html格式中直接用<a href file......>,客户就可以点击下载了.
http://www.secureblackbox.com/delphi-ssl.html
unit ReadHttpFiles;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, wininet,
StdCtrls, ComCtrls;type
TForm1 = class(TForm)
Button1: TButton;
RichEdit1: TRichEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
hIs, hIc, hIR : Hinternet;
pcbuf : pChar;
dwRead : Dword;
begin
dwRead := 0;
GetMem(pcbuf,1024);
hIs := InternetOpen('HttpGet', INTERNET_OPEN_TYPE_DIRECT,
NIL, NIL,0);
hIc := InternetConnect(hIs, 'www.microsoft.com', INTERNET_DEFAULT_HTTP_PORT,
NIL, NIL, INTERNET_SERVICE_HTTP,0,0);
hIR := HttpOpenRequest(hIC, nil, '/Default.asp', nil, nil,nil, 0,0);
if HttpSendRequest(hIR, nil, 0,nil,0) then
begin
while InternetReadFile(hIR, pcbuf,1024,dwRead) do
begin
if dwRead <= 0 then break;
RichEdit1.Text := RichEdit1.text + pcBuf;
end;
end;
InternetCloseHandle(hIR);
InternetCloseHandle(hIC);
InternetCloseHandle(hIs);
FreeMem(pcBuf);
end;end.
需要把上面例子的"www.microsoft.com"改为你上拿的网站,
"/default.asp" 改为你要的html文件.
function DownLoadInternetFile(Source, Dest : String): Boolean;
begin
try
Result := URLDownloadToFile(nil,PChar(Source),PChar(Dest),0,nil) = 0
except
Result := False;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
SourceString, DestinationString: string;
begin
//File location on the Internet.
SourceString := 'http://www.borland.com/images/homepage/del6homemural.gif';
//File destination.
DestinationString := 'C:Tempdel6homemural.gif'; if DownLoadInternetFile(SourceString, DestinationString) then
//This will display the file from your browser.
ShellExecute(Application.Handle, PChar('Open'), PChar(DestinationString), PChar(''), nil, SW_NORMAL)
else
ShowMessage('Error during Download ' + SourceString);
end;
内容 请问indy控件有没有控制Https的元件???
http://expert.csdn.net/Expert/topic/1806/1806565.xml?temp=.9563867
_______________________________________________________________________________
老兄﹐近來在什么地方發達﹐
indy的6.0以上的版本已包含了 Https的類可不﹐可以到這里下載一個更好的﹕
www.nsoftware.comTradelink現在的部分客戶也轉用了HTTPS來代替Smtp和Pop3了﹐因為更安全。