WebClient Error 403

  • C#

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Thunderbolt.

    WebClient Error 403

    Hallo,

    ich bekome immer die Fehlermeldung:
    Der Remoteserver hat einen Fehler zurückgegeben: (403) Unzulässig.

    Bedeutet diese Fehlermeldung das ich keine Zugriffsrechte habe ?
    Ich kann mich ganz normal auf dem Server Manuel anmelden.
    Es ist Absicht das keine URL's angegeben sind.
    Wie kann man das Problem Lösen ???

    C#-Quellcode

    1. public class CookiesAwareWebClient : WebClient
    2. {
    3. public CookieContainer CookieContainer;
    4. public CookieContainer MyProperty
    5. {
    6. get { return CookieContainer; }
    7. set { CookieContainer = value; }
    8. }
    9. public CookiesAwareWebClient()
    10. {
    11. CookieContainer = new CookieContainer();
    12. }
    13. protected override WebRequest GetWebRequest(Uri address)
    14. {
    15. WebRequest request = base.GetWebRequest(address);
    16. ((HttpWebRequest)request).CookieContainer = CookieContainer;
    17. return request;
    18. }
    19. }
    20. class Program
    21. {
    22. static void Main(string[] args)
    23. {
    24. Download("XXXX","XXXX","C:/","https:......");
    25. Console.ReadLine();
    26. }
    27. private static void Download(string benutzerName, string password, string destination, string downloadUri)
    28. {
    29. using (CookiesAwareWebClient client = new CookiesAwareWebClient())
    30. {
    31. NameValueCollection values = new NameValueCollection();
    32. values.Add("User name", benutzerName);
    33. values.Add("Password", password);
    34. // We authenticate first
    35. client.UploadValues("https:", values);
    36. // Now we can download
    37. string modifieduri = "http:/" + downloadUri.Replace("http:/", "") + "&rp=";
    38. string filename = System.IO.Path.GetFileName(downloadUri);
    39. string filepathname = System.IO.Path.Combine(destination, filename);
    40. client.DownloadFile(modifieduri, filepathname);
    41. }
    42. }
    43. }


    Vielen dank

    C#-Codetag eingefügt. ~Trade

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Trade“ ()