[thelist] .net webrequest help?
Peter Brunone (EasyListBox.com)
peter at easylistbox.com
Thu May 11 14:13:54 CDT 2006
Hi Scott,
This is just idle speculation, but what if you remove the Response.End and Response.Close statements? They shouldn't be strictly necessary, and I don't think I've ever used them when streaming a file to the client (or when I'm not).
HTH,
Peter
----------------------------------------
From: Scott Dexter <dexilalolai at yahoo.com>
Sent: Thursday, May 11, 2006 11:45 AM
To: thelist at lists.evolt.org
Subject: [thelist] .net webrequest help?
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