Help! The server committed a protocol violation. Section=ResponseStatusLine  
Author Message
IAmLoco





PostPosted: Visual C# General, Help! The server committed a protocol violation. Section=ResponseStatusLine Top

I've been working on my first project un C#

a simple podcast downloader for RadioPirate (an internet french Radio and also now on XM 172)

I know the code is not great (hey that's my first project ;) )

so it just download the XML file that contain all the information and export the url field and the file name in another file (CC.RPc)

read the link to download the file

the first file always complete successfully

at the second file at this particular line (WebClient.DownloadFile(input2, destination); )

it crash with this error code

A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll

The thread 0x8d4 has exited with code 0 (0x0).

A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll

A first chance exception of type 'System.Net.WebException' occurred in System.dll

An unhandled exception of type 'System.Net.WebException' occurred in System.dll

Additional information: The server committed a protocol violation. Section=ResponseStatusLine

The program '[5288] Downloader.vshost.exe: Managed' has exited with code 0 (0x0).

I have replaced some code since this radio is not free and there's some private stuf in the URL

here's the code:

using System;

using System.Net;

using System.IO;

using System.Xml;

using System.Xml.Xsl;

using System.Xml.XPath;

class RPcast

{

public static void Main()

{

//Create a new XslTransform object and load the style sheet

XslCompiledTransform xslt = new XslCompiledTransform();

xslt.Load( );

//Create a new XPathDocument and load the XML data to be transformed.

XPathDocument mydata = new XPathDocument( http://www.hide-link.com/ ;Password=###########################");

//Create an XmlTextWriter which outputs to the console.

XmlWriter writer = new XmlTextWriter("./cc.RPc", null);

//Transform the data and send the output to the console.

xslt.Transform(mydata, null, writer);

writer.Close();

StreamReader re = File.OpenText("./cc.RPc");

string input = null;

while ((input = re.ReadLine()) != null)

{

string input2 = null;

input2 = re.ReadLine();

input2 = input2.Replace("&", "&");

string destination = "c:\\" + input + ".mp3";

WebClient WebClient = new WebClient();

WebClient.DownloadFile(input2, destination);

WebClient.Dispose();

}

re.Close();

}

}

//END OF CODE

thanks for your help



Visual C#5  
 
 
IAmLoco





PostPosted: Visual C# General, Help! The server committed a protocol violation. Section=ResponseStatusLine Top

here is an example of the cc.RPc file content

mercredi 25 octobre 2006 - 06h00-07h00

http://podcast.radiopirate.com/play.mp3 username=iamlocogmailcom&password=########&type=MP3&jour=Mercredi&file=Radio-Parallele-De-Jeff-Fillion-06h00-07h00.mp3

hope this will help :)


 
 
OmegaMan





PostPosted: Visual C# General, Help! The server committed a protocol violation. Section=ResponseStatusLine Top

Couple of things that don't necessarily fix the eventual outcome but will help you minimize problems.
  1. Place you main code area in a try catch block. See Exception Handling on a good example. Note you can have your code catch specific exceptions that may be thrown...research the different ones such as by hiting F1 on the code segment such as ReadLine and reading about the class. Some classes will throw specific exceptions and you can handle them in the code.
  2. After the readline, it is good to check if what has been read is real text. The end of file or an empty line could cause the code problems. After the first input2 = Readline put in



if (string.IsNullOrEmpty( ) == false)
{
string destination = string
...
}