14th April 07:18
HTTP protocol violation
I am writing a windows app that sends an HTTP request for
xml data to a non-IIS server.
No matter what I have tried I always get back the message
"The underlying connection was closed: The server
committed an HTTP protocol violation."
They have a password challenge on the server. If I enter
the url directly into IE it prompts me for the password
which I enter. Then it returns the XML I am expecting.
I can't seem to make this work in C#. What am I doing
Here is my code...
HttpWebRequest webRequest = (HttpWebRequest)
NetworkCredential myCred = new NetworkCredential(user,pw);
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri("target url here/"),"Basic",myCred);
webRequest.Credentials = myCache;
webRequest.KeepAlive = true;
webRequest.PreAuthenticate = true; // this might be
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE
6.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR
webRequest.Accept = "image/gif, image/x-xbitmap,
image/jpeg, image/pjpeg, application/x-shockwave-flash,
*/*"; webRequest.ProtocolVersion =
// this next call always throws and exception. (HTTP
HttpWebResponse webResponse = (HttpWebResponse)