Page 1 of 11
uCoz Community » Archives » Locked » Download file from serverq
Download file from serverq
Xoemab2659
Posts: 2
Reputation: 0

Message # 1 | 3:31 PM
I try to get file programmatically from server using c# winforms. First I checking if file is there but when I make httpwebrequest using HEAD method it's return me "The remote server returned an error 403 (Forbidden)"... The downloaded file is 0kb. Any help?

Here is the code if you need it.
Code

private bool RemoteFileExists(string url)
{
      try
      {
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.Method = "HEAD";
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            return (response.StatusCode == HttpStatusCode.OK);
      }
      catch (Exception ex)
      {
            MessageBox.Show(ex.ToString());
            return false;
      }
}

private void Form1_Load(object sender, EventArgs e)
         {
             if (RemoteFileExists("http://xoemab.ucoz.ru/ConvertToUTF-8/setup.rar") == true)
             {
                 WebClient webClient = new WebClient();
                 webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
                 webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
                 webClient.DownloadFileAsync(new Uri("http://xoemab.ucoz.ru/ConvertToUTF-8/setup.rar"), @"C:\Users\Almis\Desktop\setup.rar");
             }
             else
             {
                 MessageBox.Show("You have already the latest version.");
             }
         }
Sunny
Posts: 9296
Reputation: 456

Message # 2 | 10:38 AM
Xoemab2659, it is not possible to do on uCoz.
I'm not active on the forum anymore. Please contact other forum staff.
CoffeeCone
Posts: 687
Reputation: 41

Message # 3 | 11:33 AM
Quote (Xoemab2659)
I try to get file programmatically from server using c# winforms. First I checking if file is there but when I make httpwebrequest using HEAD method it's return me "The remote server returned an error 403 (Forbidden)"... The downloaded file is 0kb. Any help?

I'm not experienced with the language that you're using but I just had a thought, maybe you can try spoofing the User-Agent string of the request to make it seem like you are accessing that URL from a browser.

"Friends don't let friends use Internet Explorer 6." - Microsoft || Join the cause. Help your friends.


uCoz Community » Archives » Locked » Download file from serverq
Page 1 of 11
Search: