对于“302 Found”我该怎么办?使用 Indy 下载时出现异常?
我正在尝试将文件下载到字符串:
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
I am trying to download a file to a string:
function FetchUrl(const url: string): string;
var
idhttp : TIdHTTP;
begin
idhttp := TIdHTTP.Create(nil);
try
Result := idhttp.Get(url);
finally
idhttp.Free;
end;
end;
What is wrong with this code? I get an exception: HTTP/1.1 302 Found
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
TIdHTTP.HandleRedirects
属性设置为 True。默认情况下为 False。Set the
TIdHTTP.HandleRedirects
property to True. It is False by default.HTTP 响应代码 302 意味着远程服务器想要将您重定向到另一个 URL,该 URL 在响应的 Location 标头中指定。您需要执行一些特殊操作来查看 Location 标头并转到该 URL。也许您的 http 库有一个选项可以自动执行此操作,因此请检查文档。
The HTTP response code 302 means the remote server wants to redirect you to another URL, which is specified in the Location header of the response. You need to do something special to look at the Location header and go to that URL. Maybe your http library has an option to do this automatically, so check the documentation.