加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 使用Indy下载时,我应该怎么做“302 Found”异常?

发布时间:2020-12-15 09:47:59 所属栏目:大数据 来源:网络整理
导读:我正在尝试将文件下载到字符串: function FetchUrl(const url: string): string;var idhttp : TIdHTTP;begin idhttp := TIdHTTP.Create(nil); try Result := idhttp.Get(url); finally idhttp.Free; end;end; 这段代码有什么问题?我得到一个例外:HTTP / 1
我正在尝试将文件下载到字符串:

function FetchUrl(const url: string): string;
var
 idhttp : TIdHTTP;
begin
  idhttp := TIdHTTP.Create(nil);
  try
    Result := idhttp.Get(url);
  finally
    idhttp.Free;
  end;
end;

这段代码有什么问题?我得到一个例外:HTTP / 1.1 302 Found

解决方法

将TIdHTTP.HandleRedirects属性设置为True.默认情况下为False.

function FetchUrl(const url: string): string; 
var 
 idhttp : TIdHTTP; 
begin 
  idhttp := TIdHTTP.Create(nil); 
  try 
    idhttp.HandleRedirects := True;
    Result := idhttp.Get(url); 
  finally 
    idhttp.Free; 
  end; 
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读