locked
How To Solve This Error - HTTP Error 500 Internal server error RRS feed

  • Question

  • HTTP Error 500 Internal server error- if (e.Error != null)

    code

     private void button1_Click(object sender, EventArgs e)
     {

    textBox1.Text="http://dl.songsmp3.com/fileDownload/Songs/0/28070.mp3";

    textBox2.Text="C:\\Users\\Mohit\\Desktop\\28070.mp3";

     Stopwatch sw = new Stopwatch();
     WebClient Download_Client = new WebClient();

     Download_Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
     Download_Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
     Download_Client.DownloadFileAsync(new Uri(textBox1.Text.Trim().ToString()), textBox2.Text.Trim());

     sw.Start();

    }

     private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
     {

     progressBar1.Value = e.ProgressPercentage;

    }

    private void Completed(object sender, AsyncCompletedEventArgs e)
    {

     if (e.Error != null)
     {

    MessageBox.Show("Error ", "Download has been canceled.", MessageBoxButtons.OK, MessageBoxIcon.Error);

    }

    }


    hitesh modani

    Tuesday, April 5, 2016 6:15 PM

Answers

  • You are getting a protocol error for this particular URL.  They are looking at the header for certain values and failing the call otherwise.  Specifically for this URL you should add the User-Agent and probably the Accept-Language values. The User-Agent must be a known agent string otherwise their site fails the call.  Here's what worked for me.

    //Need to do this before actually downloading the file
    Download_Client.Headers.Add("Accept-Language", "en-US");
    Download_Client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0");

    Michael Taylor
    http://www.michaeltaylorp3.net

    Wednesday, April 6, 2016 3:32 PM

All replies

  • Try adding this line before starting the download operation:

        Download_Client.Headers.Add( "User-Agent", "Hitesh Maheshwari" );

    Tuesday, April 5, 2016 7:06 PM
  • still not working

    hitesh modani

    Tuesday, April 5, 2016 8:06 PM
  • The 500 error is on the server side. It could be about anything, and what is happening is the server side code is blowing up,  and the Web server is throwing back the catch 22 HTTP 500 error.

    Fiddler may help you it allows you the look at the raw traffic at the time the 500 was thrown.

    Tuesday, April 5, 2016 9:49 PM
  • still not working

    Show you current code, maybe it still needs adjustments.

    Wednesday, April 6, 2016 4:41 AM
  • https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_Error

    Unless you have control of the server what you can do is pretty darn limited. You can check what might be wrong in your request that it trips up the Server. But it could be anything or nothing.

    The 400 and 500 Satus codes are "default" messages, if no more specific message is avalible or wanted by the Server programmer.
    It can mean anything from Faulty request, Faulty headers&lacking cookies or a unwanted UserAgent ID.

    Wednesday, April 6, 2016 9:43 AM
  • You are getting a protocol error for this particular URL.  They are looking at the header for certain values and failing the call otherwise.  Specifically for this URL you should add the User-Agent and probably the Accept-Language values. The User-Agent must be a known agent string otherwise their site fails the call.  Here's what worked for me.

    //Need to do this before actually downloading the file
    Download_Client.Headers.Add("Accept-Language", "en-US");
    Download_Client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0");

    Michael Taylor
    http://www.michaeltaylorp3.net

    Wednesday, April 6, 2016 3:32 PM