getting binary data with HttpWebRequest/Response

  • Thread starter Thread starter z f
  • Start date Start date
Z

z f

Hi,

I'm making HTTP request to a dynamic resource no web server.
if i get in the response headers the
Content-Disposition: attachment; filename=...
and
Content-Type: application/msword; name=...

i need to get binary data from web server.
what is the best way to do this?

i got exception
Thread was being aborted

the code i used is
StreamReader stm = new StreamReader( res.GetResponseStream() );
StreamWriter sw = new StreamWriter ( Response.OutputStream );
sw.Write ( stm.ReadToEnd() );

yes, i'm making the request from aspx page on another resource and need to
output the response.
this why the use of new StreamWriter ( Response.OutputStream );

why i get this exception?

TIA,
z.
 
z said:
Hi,

I'm making HTTP request to a dynamic resource no web server.
if i get in the response headers the
Content-Disposition: attachment; filename=...
and
Content-Type: application/msword; name=...

i need to get binary data from web server.
what is the best way to do this?

i got exception
Thread was being aborted

the code i used is
StreamReader stm = new StreamReader( res.GetResponseStream() );
StreamWriter sw = new StreamWriter ( Response.OutputStream );
sw.Write ( stm.ReadToEnd() );

yes, i'm making the request from aspx page on another resource and
need to output the response.
this why the use of new StreamWriter ( Response.OutputStream );

why i get this exception?

Because you're using StreamReader/Writer, thus thoroughly screwing up any
binary contents. Readers and Writers process *characters*. Use raw streams.

Cheers,
 
Back
Top