473,811 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

webrequest help

hi all,

given:
HttpWebRequest WebReq =
(HttpWebRequest )WebRequest.Cre ate("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp = (HttpWebRespons e)WebReq.GetRes ponse();
Response.Write( WebResp.StatusC ode);
Response.Write( WebResp.Server) ;

Stream Answer = WebResp.GetResp onseStream();
StreamReader _Answer = new StreamReader(An swer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar
Oct 14 '08 #1
8 1917
When you stream directly to the stream, you have to set the MIME type in the
page before the code that starts the stream. Once you have set the type, the
browser should recongnize the file as whatever type you have told the
browser that file is.

If that is overbearing, you can stream the file to a folder in the website
and redirect the user to that file. Just make sure you have a mechanism that
cleans up old files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

*************** *************** **************
| Think outside the box! |
*************** *************** **************
"rodchar" <ro*****@discus sions.microsoft .comwrote in message
news:BF******** *************** ***********@mic rosoft.com...
hi all,

given:
HttpWebRequest WebReq =
(HttpWebRequest )WebRequest.Cre ate("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp =
(HttpWebRespons e)WebReq.GetRes ponse();
Response.Write( WebResp.StatusC ode);
Response.Write( WebResp.Server) ;

Stream Answer = WebResp.GetResp onseStream();
StreamReader _Answer = new StreamReader(An swer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar
Oct 14 '08 #2
once i set the MIME type, how, then, do i take the stream and display it my
web page?

"Cowboy (Gregory A. Beamer)" wrote:
When you stream directly to the stream, you have to set the MIME type in the
page before the code that starts the stream. Once you have set the type, the
browser should recongnize the file as whatever type you have told the
browser that file is.

If that is overbearing, you can stream the file to a folder in the website
and redirect the user to that file. Just make sure you have a mechanism that
cleans up old files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

*************** *************** **************
| Think outside the box! |
*************** *************** **************
"rodchar" <ro*****@discus sions.microsoft .comwrote in message
news:BF******** *************** ***********@mic rosoft.com...
hi all,

given:
HttpWebRequest WebReq =
(HttpWebRequest )WebRequest.Cre ate("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp =
(HttpWebRespons e)WebReq.GetRes ponse();
Response.Write( WebResp.StatusC ode);
Response.Write( WebResp.Server) ;

Stream Answer = WebResp.GetResp onseStream();
StreamReader _Answer = new StreamReader(An swer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar

Oct 15 '08 #3
rodchar wrote:
once i set the MIME type, how, then, do i take the stream and display it
my web page?
You read the stream into a byte array, and then output the byte array into
the Response object. For a previous project, I found that adding a
content-disposition header helped (for Safari, I think).

.... your previous code ...
Stream Answer = WebResp.GetResp onseStream();

int PdfByteCount = (int)Answer.Len gth - 1;
byte[] pdfBytes = new byte[PdfByteCount];
Answer.Read(pdf Bytes, 0, PdfByteCount);

Response.ClearC ontent();
Response.ClearH eaders();
Response.AddHea der(
"Content-disposition",
"inline; filename=some_f ile_name.pdf");
Response.Conten tType = "applicatio n/pdf";
Response.Binary Write(pdfBytes) ;
Response.End();

--
Ben
http://allben.net/

Oct 15 '08 #4
Ben Amada wrote:
int PdfByteCount = (int)Answer.Len gth - 1;
byte[] pdfBytes = new byte[PdfByteCount];
Answer.Read(pdf Bytes, 0, PdfByteCount);
That's not correct, should be:

byte[] pdfBytes = new byte[Answer.Length];
Answer.Read(pdf Bytes, 0, (int)Answer.Len gth);

Oct 15 '08 #5
a pdf is webrequest response. it will replace the page with the pdf.
normally, you would have a link the user hits that returns the pdf file.
if you want it inline in the page, then you add an iframe to page, and
set the resource the pdf url.

-- bruce (sqlwork.com)

rodchar wrote:
once i set the MIME type, how, then, do i take the stream and display it my
web page?

"Cowboy (Gregory A. Beamer)" wrote:
>When you stream directly to the stream, you have to set the MIME type in the
page before the code that starts the stream. Once you have set the type, the
browser should recongnize the file as whatever type you have told the
browser that file is.

If that is overbearing, you can stream the file to a folder in the website
and redirect the user to that file. Just make sure you have a mechanism that
cleans up old files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

************** *************** ***************
| Think outside the box! |
************** *************** ***************
"rodchar" <ro*****@discus sions.microsoft .comwrote in message
news:BF******* *************** ************@mi crosoft.com...
>>hi all,

given:
HttpWebRequest WebReq =
(HttpWebReque st)WebRequest.C reate("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp =
(HttpWebRespo nse)WebReq.GetR esponse();
Response.Write( WebResp.StatusC ode);
Response.Write( WebResp.Server) ;

Stream Answer = WebResp.GetResp onseStream();
StreamReader _Answer = new StreamReader(An swer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar
Oct 15 '08 #6
i'm getting message:
This stream does not support seek operations.

Here's some of what i'm doing at the source of the url:

context.Respons e.Clear();
context.Respons e.ClearHeaders( );
context.Respons e.ClearContent( );
context.Respons e.ContentType = @"applicatio n/pdf";
//context.Respons e.AddHeader("co ntent-disposition",
String.Format(" inline; filename={0}.pd f", adNumber));
context.Respons e.AddHeader("co ntent-disposition",
String.Format(" attachment; filename={0}.pd f", adNumber));

byte[] image = new byte[fileInfo.Length];
using (BinaryReader reader = new BinaryReader(ne w
FileStream(path , FileMode.Open, FileAccess.Read )))
{
image = reader.ReadByte s((int)fileInfo .Length);
}

context.Respons e.BinaryWrite(i mage);
context.Respons e.Flush();
context.Respons e.Close();
context.Respons e.End();
"bruce barker" wrote:
a pdf is webrequest response. it will replace the page with the pdf.
normally, you would have a link the user hits that returns the pdf file.
if you want it inline in the page, then you add an iframe to page, and
set the resource the pdf url.

-- bruce (sqlwork.com)

rodchar wrote:
once i set the MIME type, how, then, do i take the stream and display it my
web page?

"Cowboy (Gregory A. Beamer)" wrote:
When you stream directly to the stream, you have to set the MIME type in the
page before the code that starts the stream. Once you have set the type, the
browser should recongnize the file as whatever type you have told the
browser that file is.

If that is overbearing, you can stream the file to a folder in the website
and redirect the user to that file. Just make sure you have a mechanism that
cleans up old files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

*************** *************** **************
| Think outside the box! |
*************** *************** **************
"rodchar" <ro*****@discus sions.microsoft .comwrote in message
news:BF******** *************** ***********@mic rosoft.com...
hi all,

given:
HttpWebRequest WebReq =
(HttpWebReques t)WebRequest.Cr eate("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp =
(HttpWebRespon se)WebReq.GetRe sponse();
Response.Write( WebResp.StatusC ode);
Response.Write( WebResp.Server) ;

Stream Answer = WebResp.GetResp onseStream();
StreamReader _Answer = new StreamReader(An swer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar
Oct 15 '08 #7
thanks everyone for the help,
rod.

"rodchar" wrote:
hi all,

given:
HttpWebRequest WebReq =
(HttpWebRequest )WebRequest.Cre ate("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp = (HttpWebRespons e)WebReq.GetRes ponse();
Response.Write( WebResp.StatusC ode);
Response.Write( WebResp.Server) ;

Stream Answer = WebResp.GetResp onseStream();
StreamReader _Answer = new StreamReader(An swer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar
Oct 16 '08 #8
You can move data from a stream to another stream. Outputting as bytes is
another option, per Ben's post (have not gone through his code yet to ensure
it is correct).

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

*************** *************** **************
| Think outside the box! |
*************** *************** **************
"rodchar" <ro*****@discus sions.microsoft .comwrote in message
news:CC******** *************** ***********@mic rosoft.com...
i'm getting message:
This stream does not support seek operations.

Here's some of what i'm doing at the source of the url:

context.Respons e.Clear();
context.Respons e.ClearHeaders( );
context.Respons e.ClearContent( );
context.Respons e.ContentType = @"applicatio n/pdf";
//context.Respons e.AddHeader("co ntent-disposition",
String.Format(" inline; filename={0}.pd f", adNumber));
context.Respons e.AddHeader("co ntent-disposition",
String.Format(" attachment; filename={0}.pd f", adNumber));

byte[] image = new byte[fileInfo.Length];
using (BinaryReader reader = new BinaryReader(ne w
FileStream(path , FileMode.Open, FileAccess.Read )))
{
image = reader.ReadByte s((int)fileInfo .Length);
}

context.Respons e.BinaryWrite(i mage);
context.Respons e.Flush();
context.Respons e.Close();
context.Respons e.End();
"bruce barker" wrote:
>a pdf is webrequest response. it will replace the page with the pdf.
normally, you would have a link the user hits that returns the pdf file.
if you want it inline in the page, then you add an iframe to page, and
set the resource the pdf url.

-- bruce (sqlwork.com)

rodchar wrote:
once i set the MIME type, how, then, do i take the stream and display
it my
web page?

"Cowboy (Gregory A. Beamer)" wrote:

When you stream directly to the stream, you have to set the MIME type
in the
page before the code that starts the stream. Once you have set the
type, the
browser should recongnize the file as whatever type you have told the
browser that file is.

If that is overbearing, you can stream the file to a folder in the
website
and redirect the user to that file. Just make sure you have a
mechanism that
cleans up old files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

************** *************** ***************
| Think outside the box! |
************** *************** ***************
"rodchar" <ro*****@discus sions.microsoft .comwrote in message
news:BF******* *************** ************@mi crosoft.com...
hi all,

given:
HttpWebRequest WebReq =
(HttpWebReque st)WebRequest.C reate("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp =
(HttpWebRespo nse)WebReq.GetR esponse();
Response.Write( WebResp.StatusC ode);
Response.Write( WebResp.Server) ;

Stream Answer = WebResp.GetResp onseStream();
StreamReader _Answer = new StreamReader(An swer);

this url is retrieving a .pdf file. how do i get my pdf file to
display on
my web page?

thanks,
rodchar
Oct 16 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3279
by: Keith Selbee | last post by:
I am trying to submit data to a webpage in the form of a post and my code is below. It is a function that takes a url and the post content as strings and then performs the post. But as soon as I add the post data to the headers I get an exception that just says "headers". Can anyone please help me here? Thanks.... public string Get(string u, string c) { WebRequest wr = WebRequest.Create(u); wr.Headers.Add(c);
17
7243
by: James Johnson | last post by:
Dear C#dex, I define a variable: HttpWebRequest webRequest and run the following request webRequest = WebRequest.Create(TARGET_URL) as HttpWebRequest; The webRequest object returns values and in the debugger I can see the value I want in the property
4
4325
by: Paul | last post by:
Hello, I tried to execute a button on an aspx webpage using WebRequest, but it failed. When posting data as if I did a login (see code), I just receive the login page, instead of the page I should get after login. The button I tried to 'push' (by adding &login=Login in de posted data, where login is the name of the login button - I verified this data by capturing the data of a request using a webbrowser) has not executed.
8
2407
by: John K. | last post by:
Hi I was wondering if it's possible to use the WebRequest class to access a file on windows shared folder with authentication? If yes, what would the syntax be? I've tried to look this up in the references available but to no avail Also, is it safer (better practise) in an LAN environment to use HTTP requests to access shared files (via ASP.NET) rather than UNC file shares TIA Regards John
12
2871
by: ThyRock | last post by:
I am working on a WebRequest accessing the US Postal Service WebTools test API. This service uses a DLL file (ShippingAPITest.dll) with a query string which includes XML. The web service accepts the query string with no url encoding. I must pass the <> characters as they are in the query string. If these characters are url encoded the service rejects the request. This API Url is http://testing.shippingapis.com/ShippingAPITest.dll
0
1328
by: Tony Archer | last post by:
Here's my problem... When I use this code to hit the site in question I'm redirected to another SSL login page. If processed successfully the page creates a cookie and then redirects you to the original request. However, my code cannot seem to hold onto the cookie it creates. Does anyone know how to do this?
2
5979
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an application to download images using System.NET classes (webclient, webrequest) asynchronously behind proxy server. The reading method works like this: System.Net.WebClient client=new System.Net.WebClient();
3
9605
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I'm trying to create a call to a web page to validate and register software. The code I'm using is: Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click Dim WebRequest As HttpWebRequest Dim instance As HttpWebRequest =...
0
1176
by: buccsailor | last post by:
Hell there, I tried to post a reply to a message thread created back in July 2006 regarding the override of WebRequest, Closed Conenctions and setting KeepAlive to false,but it's been over 60 days so I am creating a new topci in the hopes of an answer to a related issue. GhostAK suggested some vb.net code that should work to allow the setting of the Keep Alive property. yes, I am having connection close errors. The code suggested...
3
8189
by: Dave | last post by:
string m_request = some_web_page; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request ); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Which works fine, but I need to set and send a cookie with the WebRequest. How do I do that?
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.