none
The remote server returned an error: (500) Internal Server Error.

    Question

  • i try to download image file using winforms. here is my code.

    string url = "http://www.xxxx.in/im/Image.gpj";
    using (var client = new WebClient())
    using (var file = File.Create("Image.gpj"))
    {
              var bytes = client.DownloadData(url);
              file.Write(bytes, 0, bytes.Length);
    }

    but i get the exception


    error

    please help

     


    rageshS
    Friday, October 07, 2011 4:27 AM

Answers

  • There can be many reasons for that error.

    1. The url is not in the correct format. I.e. you try to access a page that really does not exist.

    2. WebClient can not imitate a real browser. It might be that this website uses cookies.

    So you have to imitate that too.

    Use HttpWebRequest which has more control over these values.

     

    Noam B.



    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...
    • Proposed as answer by Noam B Sunday, October 09, 2011 7:42 AM
    • Marked as answer by Lie YouModerator Thursday, October 13, 2011 8:59 AM
    Sunday, October 09, 2011 7:42 AM

All replies

  • maybe you need just to use :

     

    			string remoteUri = "http://www.xxxx.in/im/";
    			string fileName = "Image.jpg ", myStringWebResource = null;
    
    			WebClient myWebClient = new WebClient();
    
    			myStringWebResource = remoteUri + fileName;
    
    			myWebClient.DownloadFile(myStringWebResource,fileName);	
    Friday, October 07, 2011 6:13 PM
  • There can be many reasons for that error.

    1. The url is not in the correct format. I.e. you try to access a page that really does not exist.

    2. WebClient can not imitate a real browser. It might be that this website uses cookies.

    So you have to imitate that too.

    Use HttpWebRequest which has more control over these values.

     

    Noam B.



    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...
    • Proposed as answer by Noam B Sunday, October 09, 2011 7:42 AM
    • Marked as answer by Lie YouModerator Thursday, October 13, 2011 8:59 AM
    Sunday, October 09, 2011 7:42 AM