Stream a PDF over port 80 using an HTTP Request RRS feed

  • Question

  • User-1784654759 posted

    Can anyone help me stream a PDF to a browser?

     I want to retrieve a file over port 80 across our firewall and display the PDF on the webserver which is on the other side of the firewall.

     I get the file name from a web service but now I want to open the file.

    I have to use an http request because we dont want the tcp traffic from a file request going across the firewall.

    I am able to get a text file accross but not succesfull in getting a PDF.

     I know I have to use the context application/pdf.

    I am not to familiar with streaming and the mechanics of requesting files over http so I am kind of stuck. from the examples that i have seen I think it is not too far from the example below which is how i got the text file across.

     Any help would be appreciated. thanks

             // Creates an HttpWebRequest with the specified URL.
             HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("");
             // Sends the HttpWebRequest and waits for the response.           

             HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
             // Gets the stream associated with the response.
             Stream receiveStream = myHttpWebResponse.GetResponseStream();
             Encoding encode = System.Text.Encoding.GetEncoding("


             // Pipes the stream to a higher level stream reader with the required encoding format.
             StreamReader readStream = new StreamReader( receiveStream, encode );
    \r\nResponse stream received.");
             Char[] read = new Char[256];
             // Reads 256 characters at a time.   
             int count = readStream.Read( read, 0, 256 );
             while (count > 0)
                // Dumps the 256 characters on a string and displays the string to the console.
                String str = new String(read, 0, count);
                count = readStream.Read(read, 0, 256);
             // Releases the resources of the response.
             // Releases the resources of the Stream.

    Tuesday, January 9, 2007 1:38 PM


  • User113421904 posted


    try add http headers:

    ' set the content type to PDF
    Response.ContentType = "application/pdf"
    ' add content type header
    Response.AddHeader("Content-Type", "application/pdf")
    ' set the content disposition
    Response.AddHeader("Content-Disposition", "inline;filename=form.pdf")
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 10, 2007 3:36 AM