The Problem:
I have access to a website where I must log on and the site uses forms authentication.Once I am authenticated, I can download a song I want. But, before I can download a song, I must first fill out this survey. I it only a few questions but it is very irritating, mostly because the songs I am downloading, I have not yet heard. So I started to write an app. The problem is the music I download. I wrote the program and it works, but the end results sux. Every music file has some type of audible artifact in it.
Please listen to the beginning of these two songs to get an idea
here and
here.
Ok here is the code. Redactions are only company names and ips. I believe it has something to do with encoding. Please Help. Now for the code:
try
{
webRequest = (HttpWebRequest)HttpWebRequest.Create(downloadWebsiteString + currentFileInt.ToString());
webRequest.CookieContainer = cookieContainer;
webRequest.Credentials = CredentialCache.DefaultCredentials;
webResponse = (HttpWebResponse)webRequest.GetResponse();
fileSizeInt = (int)webResponse.ContentLength;
this.Invoke(new UpdateOverallProgressCallback(this.UpdateOverallProgress), new object[] { currentFileInt });
if (webResponse.Headers["Content-Disposition"].Contains(@"filename=""""") == true)
{
webResponse.Close();
webRequest = null;
this.Invoke(new UpdateFileFinishCallback(this.UpdateFileFinish), new object[] { currentFileInt, false });
}
else
{
contentDisposition = new ContentDisposition(webResponse.Headers["Content-Disposition"]);
receiveStream = webResponse.GetResponseStream();
inputStreamReader = new StreamReader(receiveStream, System.Text.Encoding.Default);
bufferChar = new Char[2048];
bytesReadInt = inputStreamReader.Read(bufferChar, 0, bufferChar.Length);
bytesReadRunningInt = bytesReadInt;
fileStream = new FileStream(folderString + "\\" + currentFileInt.ToString() + "_" + contentDisposition.FileName, FileMode.Create);
binaryWriter = new BinaryWriter(fileStream, System.Text.Encoding.Default);
while (bytesReadInt > 0)
{
binaryWriter.Write(bufferChar);
this.Invoke(new UpdateFileProgressCallback(this.UpdateFileProgress), new object[] { bytesReadRunningInt, fileSizeInt });
bytesReadInt = inputStreamReader.Read(bufferChar, 0, bufferChar.Length);
bytesReadRunningInt += bytesReadInt;
}
}
}
The problem has to be with the buffer size or the character encoding. Like I said, all other features work well enough. Any thoughts.
P.S. Don't bash me about my style of this or I should have used that. I got it to work using this (minus the artifacts), just help me with those please.
Thanks to all.