title: Reading Image from Web Server in C# proxy
body: <p>I am trying to write a proxy which reads an image from one server and returns it to the HttpContext supplied, but I am just getting character stream back.</p>
  
  <p>I am trying the following:</p>
  
  <pre><code>WebRequest req = WebRequest.Create(image);
  WebResponse resp = req.GetResponse();
  Stream stream = resp.GetResponseStream();
  StreamReader sr = new StreamReader(stream);
  StreamWriter sw = new StreamWriter (context.Response.OutputStream);
  
  sw.Write (sr.ReadToEnd());
  </code></pre>
  
  <p>But as I mentioned earlier, this is just responding with text.</p>
  
  <p>How do I tell it that it is an image?</p>
  
  <p>Edit: I am accessing this from within a web page in the source attribute of an img tag.  Setting the content type to application/octet-stream prompts to save the file and setting it to image/jpeg just responds with the filename.  What I want is the image to be returned and displayed by the calling page.</p>