我正在尝试将 PDF 下载到要附加到 MailMessage 的内存流中。这是我的代码:
string pdfUrl = "http://dev.domain.com/pdf+files/sample.pdf";
WebClient client = null;
MemoryStream stream;
try
{
client = new WebClient();
stream = new MemoryStream(client.DownloadData(pdfUrl));
attachments.Add(new Attachment(stream, "Sample.pdf");
}
finally
{
client.Dispose();
}
从 client.DownloadData(pdfUrl) 返回的 byte[] 长度为 0。
有任何想法吗?