从Internet上下载文件的难题,高分相送

toplor 2004-07-20 05:55:13
我想利用 Indy 控件的 TIdHttp 从Internet上下载文件。机子所在的局域网属于一个域,通过代理服务器ISA(NTLM)连上Internet。请问用 TIdHTTP 能实现从Internet上下载文件的功能吗?具体应该怎么做呢?我试了设置它的 ProxyParam,但是好像不管用,一次也没有连成功。

告诉我其它的方法实现这个功能也成。

谢谢
...全文
229 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
郝人(好人) 2004-08-09
  • 打赏
  • 举报
回复
直接使用一个控件 Thttpget就搞定了.
rejoise 2004-08-09
  • 打赏
  • 举报
回复
霜天晓竹,zhengcg(楚楚)
这个问题困扰我很久了
两位能不能把idhttp控件和修改后的代码发给我,谢谢!
hotmyemail@hotmail.com
zhengcg 2004-08-02
  • 打赏
  • 举报
回复
这个问题就比较复杂了!WebBrower是有个选项强制从URL取而不从Cache取的,TIdHTTP就不知道了。
还有,请问你是否实现了 POST 方式的 NTLM ?是否可以共享一下修改后的代码?
谢谢!
zhengcg@163.com
toplor 2004-08-02
  • 打赏
  • 举报
回复
通过修改了 Indy 的源代码,终于解决了通过 ISA(NTLM) 代理下载的问题.可是如果代理有缓存的话,TIdHTTP 会直接从缓存中取文件而不是到 URL 上下载,又出来了这个问题,不知该怎么解决.
zhengcg 2004-07-30
  • 打赏
  • 举报
回复
按 Indy 的文档,TIdHTTP 是支持 NTLM 的,但是本人在测试的时候发现有问题,我曾经在的网络也是用ISA(NTLM),主要是因为 TIdHTTP 在解释带域名的用户名时有问题,如 csdn/zhengcg,则解释后 csdn 会被丢掉。后来改了原代码才解决这个问题,不过由于本人水平所限,只能实现 GET 的操作,不能实现 POST (花了很长时间没有解决)。

至于如何如何用 TIdHTTP 下载文件,楼上已经说了,我顺便提醒一下,就是对于动态 URL(就是不是直接指向文件的 URL),必须操作两次才可以下载到文件的,第一次获取真正的URL。
蓝色光芒 2004-07-30
  • 打赏
  • 举报
回复
有这等事,把你的URL发给我,我下一下试试,我们的网络自动升级程序,就是用这个函数下的文件。
toplor 2004-07-22
  • 打赏
  • 举报
回复
TO: kiboisme(还是铁棒.....针)

帮帮我啊!!!!!

我用了你的方法调试,结果还是不行啊,文件倒是创建成功了,但是其内容却如下所示(大意是说 ISA Server 需要代理认证):

The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.

--------------------------------------------------------------------------------

Please try the following:

Click the Refresh button, or try again later.

Open the Web site home page, and then look for links to the information you want.
If you typed the page address in the Address bar, make sure that it is spelled correctly.

Verify that the Internet access policy on your network allows you to view this this page.
If you believe you should be able to view this directory or page, please contact the Web site administrator by using the e-mail address or phone number listed on the Web site home page.
HTTP 407 Proxy Authentication Required - The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied. (12209)
Internet Security and Acceleration Server

--------------------------------------------------------------------------------

Technical Information (for support personnel)

Background:
The gateway could not retrieve the requested page.

ISA Server: s01-Server
Via:

Time: 2004-7-22 1:01:22 GMT





蓝色光芒 2004-07-22
  • 打赏
  • 举报
回复
给你一个用API作的下载函数,保证好用。
//Uses WinInet

Function WWWDownFile_(Const FTURL,LocalFile : String) : Boolean; //下载函数.
Const
FTAcceptTypes = '*/*';
FTAgent = 'Explorer';
FTUserName = ''; //用户名.
FTPassword = ''; //密码.
FTPort = 80; //端口.
FTPostQuery = 'GET';
FTReferer = '';

Var
hSession, hConnect, hRequest: hInternet;
HostName, FileName: String;
f: File;
Buf: Pointer;
dwBufLen, dwIndex: DWord;
Data: Array[0..$400] of Char;
RequestMethod: PChar;
InternetFlag: DWord;
TimeOut : Cardinal;
AcceptType: LPStr;
BytesToRead,BytesReaded : DWord;
FTFileSize : integer;

Procedure ParseURL(URL: String; var HostName, FileName: String);
Var
i: Integer;
Begin
if Pos('http://', LowerCase(URL)) <> 0 then
System.Delete(URL, 1, 7);

i := Pos('/', URL);
HostName := Copy(URL, 1, i);
FileName := Copy(URL, i, Length(URL) - i + 1);
if (Length(HostName) > 0) and (HostName[Length(HostName)] = '/') then
SetLength(HostName, Length(HostName) - 1);
End;

Procedure CloseHandles;
begin
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
end;

begin
TimeOut := 6000000;
ParseURL(FTURL, HostName, FileName);
RequestMethod := PChar(FTPostQuery); // 'GET'
InternetFlag := 0;
AcceptType := PChar('Accept: ' + FTAcceptTypes);

if FTAgent <> '' then
hSession := InternetOpen(PChar(FTAgent),
INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0)
else
hSession := InternetOpen(nil,
INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);

hConnect := InternetConnect(hSession, PChar(HostName),
FTPort, PChar(FTUserName), PChar(FTPassword),
INTERNET_SERVICE_HTTP, 0, 0);
hRequest := HttpOpenRequest(hConnect, RequestMethod, PChar(FileName), 'HTTP/1.1',
PChar(FTReferer), @AcceptType, InternetFlag, 0);
InternetSetOption(hRequest, INTERNET_OPTION_CONNECT_TIMEOUT,
@TimeOut, SizeOf(TimeOut));
InternetSetOption(hRequest, INTERNET_OPTION_DATA_RECEIVE_TIMEOUT,
@TimeOut, SizeOf(TimeOut));


if FTPostQuery = '' then
HttpSendRequest(hRequest, nil, 0, nil, 0)
else
HttpSendRequest(hRequest, 'Content-Type: application/x-www-form-urlencoded', 47,
PChar(FTPostQuery), Length(FTPostQuery));

dwIndex := 0;
dwBufLen := 1024;
GetMem(Buf, dwBufLen);

Result := HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH,
Buf, dwBufLen, dwIndex);

if Result then begin
BytesReaded := 0;
FTFileSize := StrToInt(StrPas(Buf));
AssignFile(f, LocalFile);
Rewrite(f, 1);
while True do begin
if not InternetReadFile(hRequest, @Data, SizeOf(Data), BytesToRead) then
break
else if BytesToRead = 0 then Break
else
BlockWrite(f, Data, BytesToRead);
BytesReaded := BytesReaded + BytesToRead;
End;
Result := FTFileSize = Integer(BytesReaded);
CloseFile(f);
End;
FreeMem(Buf);
CloseHandles;
end;

ly_liuyang 2004-07-21
  • 打赏
  • 举报
回复
自己拓展IdHTTP的代理功能就可以了
用NTLM方法的代理,要去看MSDN了

NTLM是一般组件不支持的,你需要自己写代码,这不是分数的问题,免费代码怕就写的人很少了,去国外站点看看,有机会的都可以找到Free的
toplor 2004-07-21
  • 打赏
  • 举报
回复
To:bigben2008(ben)
那个文件放在 HTTP 服务器上啊,用FTP能下载吗?
老本 2004-07-21
  • 打赏
  • 举报
回复
上传请用HTTP,下载请用FTP。
你直接采用IE可以下载的话,就应该没有问题的。
toplor 2004-07-21
  • 打赏
  • 举报
回复
怎么没人回答啊,分不够可以再加。
toplor 2004-07-21
  • 打赏
  • 举报
回复
TO: ly_liuyang(Liu Yang)

“自己拓展IdHTTP的代理功能就可以了”

请问具体应该怎么拓?我试了 Idhttp.ProxyParams.Authentication 也不行,也许我的写法不对。能否告诉我具体应该怎么弄,谢谢!!!!!


1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧