一个关于Indy的问题(50分)

  • 主题发起人 主题发起人 WilliamJia
  • 开始时间 开始时间
W

WilliamJia

Unregistered / Unconfirmed
GUEST, unregistred user!
用Indy控件取以下URL的源文件时会出现重定向错误(Http/1.1 301),请问是什么原因,该如何解决?

URL:= 'http://www.nytimes.com/2006/07/03/technology/03lulu.html'

源码如下:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP,strUtils, OleCtrls, SHDocVw;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
IdHTTP1: TIdHTTP;
Edit1: TEdit;
WebBrowser1: TWebBrowser;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
url: String;
html: String;
TmpStream: TStringStream;

begin
TmpStream := TStringStream.Create('');
url := 'http://www.nytimes.com/2006/07/03/technology/03lulu.html';
//url := 'http://www.sciam.com/article.cfm?chanID=sa003&articleID=0006B51F-9073-14A5-907383414B7F0000';
idHttp1.Head(url);
//WebBrowser1.Navigate(url);

Memo1.Lines.Add(IdHttp1.Request.ContentType);
end;

end.
 
idhttp1.HandleRedirects:= true; //必须支持重定向否则可能出错
idhttp1.ReadTimeout:= CONST_ReadTimeout; //超过这个时间则不再访问
idhttp1.ConnectTimeout:=CONST_ReadTimeout;
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
 
接受答案了.
 
idhttp1.ConnectTimeout:=CONST_ReadTimeout;
不过indy9中没有ConnectTimeout这个属性
 
indy 9.014 有ConnectTimeout属性
如果你的没有就去掉
 
后退
顶部