TDownloadURL无法从HTTPS下载 [英] TDownloadURL cannot download from HTTPS

查看:171
本文介绍了TDownloadURL无法从HTTPS下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试通过TDownloadURL类创建(TFileStream)PDF,但是我真的遇到了从URL获取文件/流的麻烦,特别是如果URL是HTTPS。

I've been trying to create (TFileStream) a PDF through the TDownloadURL class, but I'm really having troubles in obtaining the file/stream from the URL, specially if the URL a HTTPS.

我不确定我是否清楚,但我会发布一个片段,这样可能有助于理解:

I'm not sure if I was clear, but I will post a snippet so it might help understanding:

implementation
var pdfStreamed: TDownloadUrl;
var fileStream : TFileStream;
  procedure generateStream;
  begin
    pdfStreamed:= TDownLoadURL.Create(nil);
    with pdfStreamed do
      begin
        URL := 'https://farm9.staticflickr.com/8327/8106108098_08e298f0d9_b.jpg'; //stream;
        FileName := 'D:\';
        ExecuteTarget(nil);
//        Execute;
      end;
  end;

HTTP属性在HTTPS中都存在!但它抛出了一个错误:
异常类异常消息'下载URL时出错: https://farm9.staticflickr .com / 8327 / 8106108098_08e298f0d9_b.jpg '。

The URL property exists both in HTTP as in HTTPS! But it throws me an error: Exception class Exception with message 'Error downloading URL: https://farm9.staticflickr.com/8327/8106108098_08e298f0d9_b.jpg'.

可以指出我做错了什么?我已经搜索了很多,但找不到任何有用的东西!

Could point what am I doing wrong? I've searched a lot for this, but couldn't find anything that work and simple!

非常感谢!

推荐答案

TDownloadURL 只是微软的一个薄包装 URLDownloadToFile() 功能,支持HTTPS就好了。

TDownloadURL is just a thin wrapper around Microsoft's URLDownloadToFile() function, which supports HTTPS just fine.

TDownloadURL 没有告诉你为什么 URLDownloadToFile()失败,不幸的是。但是,我可以看到您将 FileName 属性设置为文件夹路径,但您需要将其设置为目标文件的完整路径和文件名,即将被创建以保存下载的数据。 IOW,改变这个:

TDownloadURL does not tell you why URLDownloadToFile() fails, unfortunately. However, I can see that you are setting the FileName property to just a folder path, but you need to instead set it to the full path and filename of the destination file that is going to be created to hold the downloaded data. IOW, change this:

FileName := 'D:\';

对此:

FileName := 'D:\8106108098_08e298f0d9_b.jpg';

这篇关于TDownloadURL无法从HTTPS下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆