我有这样的网址" https://site.com/cgi-bin/somescript.pl?file = 12345.pdf& type = application / pdf"。当我转到这个网址时,它会在我的浏览器中以iframe显示pdf。是否可以保存此pdf?我正在考虑获取http响应流并将其转储到文件中。请指教。感谢。
答案 0 :(得分:2)
这样的事情会起作用
const string FILE_PATH = "C:\\foo.pdf";
const string DOWNLOADER_URI = "https://site.com/cgi-bin/somescript.pl?file=12345.pdf&type=application/pdf";
using (var writeStream = File.OpenWrite(FILE_PATH))
{
var httpRequest = WebRequest.Create(DOWNLOADER_URI) as HttpWebRequest;
var httpResponse = httpRequest.GetResponse();
httpResponse.GetResponseStream().CopyTo(writeStream);
writeStream.Close();
}