怎么用程序实现。
下载如:
http://www.xxx.com/down.asp?downid=1
用IE打开这个就会提示自动下载保存的位置。
我自己在软件中
把这个下载到自己的目录中。
并且原文件名和他的文件相同。
我用了TNMHTTP。不行啊。
如果直接是http://www.xxx.com/abc.exe
就可以。
下载如:
http://www.xxx.com/down.asp?downid=1
用IE打开这个就会提示自动下载保存的位置。
我自己在软件中
把这个下载到自己的目录中。
并且原文件名和他的文件相同。
我用了TNMHTTP。不行啊。
如果直接是http://www.xxx.com/abc.exe
就可以。
解决方案 »
- XML文档问题
- 急:遍历容器上的控件?
- 用webbrowser显法网页,不能一屏显示所有内容,出现滚动条,有没有通过抓图的方法将整个页面抓下来啊
- 如何另存WORD里的图片到本地为GIF格式?
- 关于MediaPlayer的问题
- 请高手进来!
- 在用DELPHI6连接SQL2000时,为何不能连接?
- 大于32k的图片如何从sql server 中取出?用dbimage按条件显示总有一块是黑的?
- 为什么不能给控件的方法加上侦测消息的语句?
- 谁有组件:ABC For Delphi 5.0,带源码的?
- 请教!我动态生成了一些控件,然后加了一个click事件,请问如何确定哪个是选定的控件?
- 请使用 IBX 控件的高手进来
输入这样的地址他都可以下载的!自己先顶一下。
他应该在对应的Down.asp中建立了对应的下载地址!除非你的程序能智能的分析别人的down.asp的代码!
不过从网上找了一个用ftp下载文件的例子或许有帮助 共同研究吧:
uses
WinInet, ComCtrls;function FtpDownloadFile(strHost, strUser, strPwd: string;Port: Integer; ftpDir, ftpFile, TargetFile: string; ProgressBar: TProgressBar): Boolean;function FmtFileSize(Size: Integer): string;beginif Size >= $F4240 thenResult := Format('%.2f', [Size / $F4240]) + ' Mb'elseif Size < 1000 thenResult := IntToStr(Size) + ' bytes'elseResult := Format('%.2f', [Size / 1000]) + ' Kb';end;constREAD_BUFFERSIZE = 4096; // or 256, 512, ...varhNet, hFTP, hFile: HINTERNET;buffer: array[0..READ_BUFFERSIZE - 1] of Char;bufsize, dwBytesRead, fileSize: DWORD;sRec: TWin32FindData;strStatus: string;LocalFile: file;bSuccess: Boolean;beginResult := False;{ Open an internet session }hNet := InternetOpen('Program_Name', // AgentINTERNET_OPEN_TYPE_PRECONFIG, // AccessTypenil, // ProxyNamenil, // ProxyBypass0); // or INTERNET_FLAG_ASYNC / INTERNET_FLAG_OFFLINE{Agent contains the name of the application orentity calling the Internet functions}
{ See if connection handle is valid }if hNet = nil thenbeginShowMessage('Unable to get access to WinInet.Dll');Exit;end;{ Connect to the FTP Server }hFTP := InternetConnect(hNet, // Handle from InternetOpenPChar(strHost), // FTP serverport, // (INTERNET_DEFAULT_FTP_PORT),PChar(StrUser), // usernamePChar(strPwd), // passwordINTERNET_SERVICE_FTP, // FTP, HTTP, or Gopher?0, // flag: 0 or INTERNET_FLAG_PASSIVE0);// User defined number for callbackif hFTP = nil thenbeginInternetCloseHandle(hNet);ShowMessage(Format('Host "%s" is not available',[strHost]));Exit;end;{ Change directory }bSuccess := FtpSetCurrentDirectory(hFTP, PChar(ftpDir));if not bSuccess thenbeginInternetCloseHandle(hFTP);InternetCloseHandle(hNet);ShowMessage(Format('Cannot set directory to %s.',[ftpDir]));Exit;end;{ Read size of file }if FtpFindFirstFile(hFTP, PChar(ftpFile), sRec, 0, 0) <> nil thenbeginfileSize := sRec.nFileSizeLow;// fileLastWritetime := sRec.lastWriteTimeend elsebeginInternetCloseHandle(hFTP);InternetCloseHandle(hNet);ShowMessage(Format('Cannot find file ',[ftpFile]));Exit;end;{ Open the file }hFile := FtpOpenFile(hFTP, // Handle to the ftp sessionPChar(ftpFile), // filenameGENERIC_READ, // dwAccessFTP_TRANSFER_TYPE_BINARY, // dwFlags0); // This is the context used for callbacks.if hFile = nil thenbeginInternetCloseHandle(hFTP);InternetCloseHandle(hNet);Exit;end;{ Create a new local file }AssignFile(LocalFile, TargetFile);{$i-}Rewrite(LocalFile, 1);{$i+}if IOResult <> 0 thenbeginInternetCloseHandle(hFile);InternetCloseHandle(hFTP);InternetCloseHandle(hNet);Exit;end;dwBytesRead := 0;bufsize := READ_BUFFERSIZE;while (bufsize > 0) dobeginApplication.ProcessMessages;if not InternetReadFile(hFile,@buffer, // address of a buffer that receives the dataREAD_BUFFERSIZE, // number of bytes to read from the filebufsize) then Break; // receives the actual number of bytes readif (bufsize > 0) and (bufsize <= READ_BUFFERSIZE) thenBlockWrite(LocalFile, buffer, bufsize);dwBytesRead := dwBytesRead + bufsize;{ Show Progress }ProgressBar.Position := Round(dwBytesRead * 100 / fileSize);Form1.Label1.Caption := Format('%s of %s / %d %%',[FmtFileSize(dwBytesRead),FmtFileSize(fileSize) ,ProgressBar.Position]);end;CloseFile(LocalFile);InternetCloseHandle(hFile);InternetCloseHandle(hFTP);InternetCloseHandle(hNet);Result := True;end;
在写文档的上传和下载 如果老兄有好的例子,请给我介绍一下
谢谢!
[email protected]
就对最后的字符串进行分析。
如果,最后的字符串包含有'.PHP?'or '.aps?',or'.xml?','.dll?','.apsx?'等等就再进一步读取网页。可能有这样的API,WINDOWS MESSAGE。看看吧。
FLASHGET是怎么搞的啊?
我真他妈不想活了。
uses
URLMon, ShellApi;function DownloadFile(SourceFile, DestFile: string): Boolean;begintryResult := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;exceptResult := False;end;end;procedure TForm1.Button1Click(Sender: TObject);const// URL LocationSourceFile = 'http://www.google.com/intl/de/images/home_title.gif';// Where to save the fileDestFile = 'c:image.gif';beginif DownloadFile(SourceFile, DestFile) thenbeginShowMessage('Download succesful!');// Show downloaded image in your browserShellExecute(Application.Handle, PChar('open'), PChar(DestFile),PChar(''), nil, SW_NORMAL)endelseShowMessage('Error while downloading ' + SourceFile)end;// Minimum availability: Internet Explorer 3.0// Minimum operating systems Windows NT 4.0, Windows 95******************************2.}usesWininet;function DownloadURL(const aUrl: string): Boolean;varhSession: HINTERNET;hService: HINTERNET;lpBuffer: array[0..1024 + 1] of Char;dwBytesRead: DWORD;beginResult := False;// hSession := InternetOpen( 'MyApp', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);tryif Assigned(hSession) thenbeginhService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, 0, 0);if Assigned(hService) thentrywhile True dobegindwBytesRead := 1024;InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead);if dwBytesRead = 0 then break;lpBuffer[dwBytesRead] := #0;Form1.Memo1.Lines.Add(lpBuffer);end;Result := True;finallyInternetCloseHandle(hService);end;end;finallyInternetCloseHandle(hSession);end;end;******************************在Delphi中如何从网络中提取一个文件到本地计算机中,如提取<BR> http://www.abcdefg.com/software/a.zip到本地指定的目录中?在窗体中添加1个TNMHTTP控件(在FastNet页)然后在随便那个Button什么的下面加入如下代码: NMHTTP1.InputFileMode := ture;NMHTTP1.Body := '本地文件名';NMHTTP1.Header := 'Head.txt';NMHTTP1.OutputFileMode := FALSE;NMHTTP1.ReportLevel := Status_Basic;NMHTTP1.Proxy := '代理服务器的IP地址';NMHTTP1.ProxyPort := '代理服务器的端口号';With NMHTTP1.HeaderInfo doBeginCookie := '';LocalMailAddress := '';LocalProgram := '';Referer := '';UserID := '用户名称';Password := '用户口令';End;NMHTTP1.Get(‘http://www.abcdefg.com/software/a.zip’);试试吧,Delphi的目录中有TNMHTTP控件的例子。NT4+,Win95+,IE3+,你可以用URL Moniker的功能。uses URLMon;...OleCheck(URLDownloadToFile(nil,'URL','Filename',0,nil));其中最后一个参数你还可以传入一个IBindStatusCallback的实现以跟踪下载进度或控制中止下载。简单的场合一句话就搞定了。
不过是:
NMHTTP1.Get(‘http://www.abcdefg.com/software/a.zip’);而不是
NMHTTP1.Get(‘http://www.abcdefg.com/software/donw.asp?id=1’);
我要下载这个
请看这里。
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.Button3Click(Sender: TObject);
var FileOnNet, LocalFileName: string;
begin
FileOnNet:='http://www.xxx.com/downing.asp?id=39';
LocalFileName:='File Downloaded From the Net.zip';
if GetInetFile(FileOnNet,LocalFileName)=True then
ShowMessage('Download successful')
else
ShowMessage('Error in file download')
end;
呵呵.再次调整一下.也把引用贴出来。
去去其他一些专门提供下载(大多是电影网站)的论坛,那里经常介绍一些下载技巧,其中就有将http://www.xxx.com/downing.asp?id=39解读成为http://www.xxx.com/zz.exe的方法,你读了之后会有启发,最好写出自己的算法~~~~~~~