C
casey chesnut
I'm writing a .NET 2003 C# WinForm application that needs to display the
thumbnails for videos from yahoo search.
Can get the video search results, which include the url to the thumbnail.
But when I try to download the thumbnail image, I keep getting a
SystemProtocolViolation.
I've tried 2 different methods, and both fail for yahoo thumbnails (although
they work for other images on the web).
string url = "http://re2.mm-b1.yimg.com/image/1626538472"; //fails
//string url = "http://www.mperfect.net/blog/bNbLogo4.jpg"; //works
Technique 1 :
WebClient wc = new WebClient();
Stream s = wc.OpenRead(url);
pictureBox1.Image = Image.FromStream(s); s.Close();
Technique 2:
HttpWebRequest wReq = (HttpWebRequest) WebRequest.Create(url); wReq.Accept =
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*"; wReq.UserAgent =
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705;
..NET CLR 1.1.4322; InfoPath.1; Media Center PC 4.0; .NET CLR 2.0.50727)";
wReq.Headers.Add("Accept-Encoding", "gzip, deflate");
wReq.Headers.Add("UA-CPU", "x86");
wReq.Headers.Add("Accept-Language","en-us");
//wReq.KeepAlive = false;
//wReq.ProtocolVersion = HttpVersion.Version10; HttpWebResponse wResp =
(HttpWebResponse) wReq.GetResponse(); Stream s = wResp.GetResponseStream();
Image i = Image.FromStream(s); s.Close();
I've also tried WebRequest, which is slightly more generic than
HttpWebRequest.
Any ideas on how to get around this?
Thanks,
casey
thumbnails for videos from yahoo search.
Can get the video search results, which include the url to the thumbnail.
But when I try to download the thumbnail image, I keep getting a
SystemProtocolViolation.
I've tried 2 different methods, and both fail for yahoo thumbnails (although
they work for other images on the web).
string url = "http://re2.mm-b1.yimg.com/image/1626538472"; //fails
//string url = "http://www.mperfect.net/blog/bNbLogo4.jpg"; //works
Technique 1 :
WebClient wc = new WebClient();
Stream s = wc.OpenRead(url);
pictureBox1.Image = Image.FromStream(s); s.Close();
Technique 2:
HttpWebRequest wReq = (HttpWebRequest) WebRequest.Create(url); wReq.Accept =
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword, */*"; wReq.UserAgent =
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705;
..NET CLR 1.1.4322; InfoPath.1; Media Center PC 4.0; .NET CLR 2.0.50727)";
wReq.Headers.Add("Accept-Encoding", "gzip, deflate");
wReq.Headers.Add("UA-CPU", "x86");
wReq.Headers.Add("Accept-Language","en-us");
//wReq.KeepAlive = false;
//wReq.ProtocolVersion = HttpVersion.Version10; HttpWebResponse wResp =
(HttpWebResponse) wReq.GetResponse(); Stream s = wResp.GetResponseStream();
Image i = Image.FromStream(s); s.Close();
I've also tried WebRequest, which is slightly more generic than
HttpWebRequest.
Any ideas on how to get around this?
Thanks,
casey