Autor Beitrag
BlackMatrix
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 243
Erhaltene Danke: 1



BeitragVerfasst: So 28.03.10 14:58 
Hi.

Ich möchte ein Bild aus dem Internet auf meinen Computer laden. Habe mir dazu folgende Methode geschrieben:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
                request.CookieContainer = cookiecontainer;
                request.UserAgent = useragent;
                HttpWebResponse httpWebReponse = (HttpWebResponse)request.GetResponse();
                Stream stream = httpWebReponse.GetResponseStream();
                Image image = Image.FromStream(stream);


Und bei Image image = Image.FromStream(stream); kommt es zu einer Exception: "Ungültiger Parameter".

Gebe ich die URL in meinen Firefox ein, dauert es etwa 15 Sekunden, dann ist das Bild da. Wie erreiche ich, dass auch mein Programm das Bild trotzdem bekommt?
norman2306
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 222
Erhaltene Danke: 16

Win XP, Win 7 64-Bit
C# 4.0 (VS2010)
BeitragVerfasst: So 28.03.10 16:17 
Der Fehler tritt auf, wenn sich in dem Stream kein Bild befindet, daher, wenn die url nicht auf ein gültiges Bild verweist.
BlackMatrix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 243
Erhaltene Danke: 1



BeitragVerfasst: So 28.03.10 17:31 
Alles klar. Ich habe mal meine Cookies im Firefox gelöscht und die Seite aufgerufen. Dann gibts kein Bild. Vermutlich stimmt etwas mit meinem CookieContainer nicht.