How do I use C # and ASP.net for a WebRequest proxy?
2 answers
No, but you can of course copy the data either synchronously or asynchronously.
- Allocate a buffer (e.g. 4kb size)
- Do a read that will either return the number of bytes read or 0 if the end of the stream has been reached.
- If the data was received, write the number of reads and cycles per read
Same:
using (Stream answer = webResp.GetResponseStream()) {
byte[] buffer = new byte[4096];
for (int read = answer.Read(buffer, 0, buffer.Length); read > 0; read = answer.Read(buffer, 0, buffer.Length)) {
Response.OutputStream.Write(buffer, 0, read);
}
}
+5
a source to share
This answer has a method CopyStream
for copying data between threads (and also points to a built-in way to do this in .NET 4).
You can do something like:
using (stream answer = WebResp.GetResponseStream())
{
CopyStream(answer, Response.OutputStream);
Response.Flush();
}
+3
a source to share