Slow download speed, large file

  • Thread starter Thread starter humbleaptience
  • Start date Start date
H

humbleaptience

I have a php script that did this before, I want to move it to asp.net

I am getting ~30kbps download speeds with this asp.net code. The php
seems to be lightening fast.

Help!

HttpWebRequest webreq = WebRequest.Create(WMSReq.ToString()) as
HttpWebRequest;
HttpWebResponse webrep = webreq.GetResponse()
as HttpWebResponse;
System.IO.Stream streamResp =
webrep.GetResponseStream();
int readbytes = 0;

Response.ClearContent();
string imgtype = "";

if (fileformat.Substring(0, 1).ToUpper() ==
"P")
{
Response.ContentType = "image/PNG";
}
else if (fileformat.Substring(0, 1).ToUpper()
== "J")
{
Response.ContentType = "image/JPEG";
}
else if (fileformat.Substring(0, 1).ToUpper()
== "T")
{
Response.ContentType = "image/TIF";
}

Response.Buffer =
false;
byte[] responseBuffer = new byte[32768];
Server.ScriptTimeout = 600;
while ((readbytes =
streamResp.Read(responseBuffer, 0, responseBuffer.Length)) > 0)
{
if (Response.IsClientConnected == true)
Response.OutputStream.Write(responseBuffer, 0, readbytes);
Response.Flush();
}
streamResp.Close();
Response.End();
 
php is faster, but you should be close. couple things to go faster.

1) turn off page buffering
2) only flush after the loop.
3) if you are just streaming a file use TransmitFile

-- bruce (sqlwork.com)
 
Back
Top