Home All Groups Group Topic Archive Search About

ServerProtocolViolation with HttpWebRequest

Author
8 Feb 2006 12:50 AM
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

Author
8 Feb 2006 1:17 AM
casey chesnut
nevermind, i just used TcpClient instead.

anyway, it looks like the yahoo server is separating the HTTP Header from
the Body using \n\n instead of \r\n\r\n ... so that is why i'm assuming
HttpWebRequest fails?

Thanks,
casey

Show quote
"casey chesnut" <casey@MORE_SPAMbrains-N-brawn.com> wrote in message
news:uewzqmELGHA.360@TK2MSFTNGP12.phx.gbl...
> 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
>
Author
8 Feb 2006 7:10 AM
Joerg Jooss
Thus wrote casey,

> nevermind, i just used TcpClient instead.
>
> anyway, it looks like the yahoo server is separating the HTTP Header
> from the Body using \n\n instead of \r\n\r\n ... so that is why i'm
> assuming HttpWebRequest fails?

Yes, that's a protocol violation.

Sigh... it's 2006 and some still people can't even get a standard HTTP line
break right.

--
Joerg Jooss
news-re***@joergjooss.de

AddThis Social Bookmark Button