3

I have a url like this "https://site.com/cgi-bin/somescript.pl?file=12345.pdf&type=application/pdf". When i go to this url it will dispaly an pdf in my browser in an iframe. Is it possible to save this pdf? I am thinking of getting the http response stream and dump it into a file. Please advice. Thanks.

0

1 Answer 1

2

Something like this would work

             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();
            }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.