非常着急的问题,请各位大侠帮我看看:IDHttp通过代理下载文件出错(100分)

  • 主题发起人 主题发起人 feizaihz
  • 开始时间 开始时间
F

feizaihz

Unregistered / Unconfirmed
GUEST, unregistred user!
我用的是Dephi6 自己带的indy,使用IDHttp来下载文件,对于有代理的情况,也设置了代理相关的参数,但是结果就是出错,
出错的主要信息是:错误代码: 407 Proxy Authentication Required。The ISA Server requires authorization to fulfill the request. Access to the Web Proxy service is denied
但是通过IE却能够正常下载,没有代理的情况下程序运行都很正常,主要的源代码如下:

说明:
ProxyObject是自己定义的一个代理信息的对象。


procedure TThreadHttp.Execute;
var
MyDownLoadFile:TFileStream;
tStream: TFileStream;
aFile: string;

function DownLoad:Boolean;
begin
Try
//设置缓存过期时间
IdHTTP.Request.Expires:=Now-1;
//不使用缓存,我附加的
//与以前的服务器兼容
IdHTTP.Request.ExtraHeaders.Add('Pragma: no-cache');
//不使用缓存新的
IdHTTP.Request.ExtraHeaders.Add('Cache-Control: no-cache');
IdHTTP.Get(SourceFile,MyDownLoadFile);
Result:=True;
Except
Result:=False;
end;
end;

begin
FreeOnTerminate := True;

IdHTTP := TIdHTTP.Create(nil);
IdHttp.OnConnected:=DSDownLoadWin.IdHTTPConnected;
IdHttp.OnDisconnected:=DSDownLoadWin.IdHTTPDisconnected;
IdHTTP.OnWork:=DSDownLoadWin.IdHTTPWork;
IdHTTP.OnWorkBegin:=DSDownLoadWin.IdHTTPWorkBegin;
IdHTTP.OnWorkEnd :=DSDownLoadWin.IdHTTPWorkEnd;

//如果需要使用代理信息
if ProxyObject.UseProxy then
begin
IdHTTP.Request.ProxyServer:=ProxyObject.ProxyServer;
IdHTTP.Request.ProxyPort:=ProxyObject.ProxyPort;
IdHTTP.Request.ProxyUsername:=ProxyObject.UserName;
IdHTTP.Request.ProxyPassword:=ProxyObject.PassWord;
end;

Try
Try
if FileExists(DestFile) then
MyDownLoadFile := TFileStream.Create(DestFile, fmOpenWrite)
else
MyDownLoadFile:=TFileStream.Create(DestFile,fmCreate);
Success:=DownLoad;
except
Success:=False;
IdHTTP.DisconnectSocket;
end;
Finally
MyDownLoadFile.Free;
if Success=False then DeleteFile(PChar(DestFile));
IdHTTP.DisconnectSocket;
DSDownLoadWin.Success:=Success;
DSDownLoadWin.HaveDownLoad:=True;
FreeAndNil(IdHTTP);
end;
end;
 
大家都没有碰到过类似问题吗?自己顶一下
 
这里有个获取代理后面的IP的例子,你参考看看能否帮你解决问题:
procedure TForm1.Button1Click(Sender: TObject);
var
IPSTR, IP, HP: string;
BeginIP, EndIP, i: Integer;
begin
HP := 'http://www.my-server.de/cgi-bin/GiveMeMyIp.pl';
NMHTTP1.Get(HP); //可否改为IdHTTP.Get(HP);
IPSTR := (NMHTTP1.Body); //可否改为IdHTTP.Body;
BeginIP := Pos('BEGINIP', IPSTR) + Length('BEGINIP');
EndIP := Pos('ENDIP', IPSTR);
for i := BeginIP to ENDip - 1 do
IP := IP + IPstr;
end;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
801
import
I
后退
顶部