3

我有一个像这样的网址“https://site.com/cgi-bin/somescript.pl?file=12345.pdf&type=application/pdf”。当我转到此网址时,它将在 iframe 中的浏览器中显示 pdf。这个pdf可以保存吗?我正在考虑获取http响应流并将其转储到文件中。请指教。谢谢。

4

1 回答 1

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();
            }
于 2012-08-14T15:46:32.553 回答