Pdf WebClient.DownloadData()返回0字节
我正在尝试将PDF下载到内存流中,并将其附加到邮件消息中。这是我的密码:Pdf WebClient.DownloadData()返回0字节,pdf,Pdf,我正在尝试将PDF下载到内存流中,并将其附加到邮件消息中。这是我的密码: 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)); attac
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.DownloadDatapdfUrl返回的字节[]长度为0
有什么想法吗?为什么可以从web浏览器下载,但以编程方式尝试时失败了,原因有很多。这些原因包括:缺少cookie(包括身份验证令牌)、方法POST与GET不匹配、缺少表单字段、不同的HTTP头、重定向问题等 有关如何解决问题的更多信息,请查看 如果我必须猜测您的情况中出现了什么问题,我会猜测是缺少cookie还是HTTP头