[thelist] .net webrequest help?

Scott Dexter dexilalolai at yahoo.com
Thu May 11 13:43:34 CDT 2006


I'm trying to grab a pdf document from one site, slurp it in, then spit it out to the browser. Why? I have to pass authentication information so the end user doesn't have to do it. So anyhows, I'm like 90% there. I get the pdf from the site, but when I spit it out to the browser, I get a blank pdf; it's like not all the data is getting streamed to the browser.


Here's the code:

                        CredentialCache myCache = new CredentialCache();
                        myCache.Add(new Uri(URL),"Basic",new NetworkCredential("userid","password"));
                        // 2) set up the request
                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
                        // Set credentials to use for this request.
                        request.Credentials = myCache;
                        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                        // Write data into Output Stream
                        StreamReader sr = new StreamReader(response.GetResponseStream());
                        Response.ContentType = response.ContentType;
                        Response.AppendHeader("Content-Disposition", "inline;filename=mypdf.pdf");
                        Response.BufferOutput=false;
                        Response.Buffer=false;
                        Response.Output.Write(sr.ReadToEnd());
                        Response.Flush();
                        // End the page
                        Response.End();
                        // Release the resources held by response object.
                        response.Close();


Anyone have ideas where I'm going wrong?

Thanks--
sgd





More information about the thelist mailing list