Slow download speed, large file

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();
 
B

bruce barker

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top