Hi,
I'm experiencing problems when doing webrequests that requires authentication with the HttpWebRequest component in an environment with a cache proxy (squid). The HttpWebRequest is configured with credentials before the request is sent and keep-alive is enabled. What happens is that the webserver responds with a 401 with Content-Length 236 to the first request (the one with no authorization headers). The HttpWebRequest component sends out a new request with the authorization headers before the IP packet with the content of the 401 is received. The content of the 401 is therefore tried parsed as the header of the response to the authenticated request. This causes a protocol violation and a webexception is thrown.
Cap from ethereal:
GET http://10.0.0.1/somepage.html HTTP/1.1
User-Agent: My Http User Agent
Host: 10.0.0.1
Proxy-Connection: Keep-Alive
HTTP/1.0 401 Unauthorized
Pragma: no-cache
<authorization headers..>
Content-Type: text/html
Content-Length: 236
X-Cache: MISS from my.corp.cache
Proxy-Connection: keep-alive
GET http://10.0.0.1/somepage.html HTTP/1.1
User-Agent: My Http User Agent
<authorization header>
Host: 10.0.0.1
Proxy-Connection: Keep-Alive
<HTML>
<HEAD>
<TITLE>Error 401</TITLE>
<META HTTP-EQUIV="Pragma" Content="no-cache">
<META HTTP-EQUIV="Expires" Content="0">
</HEAD>
<BODY>
<P><H2>HTTP Error 401</H2>
<P><STRONG>401 Unauthorized</STRONG>
<P>
</BODY>
</HTML>
HTTP/1.0 200 OK
Pragma: no-cache
Content-Type: text/xml
Content-Length: 9713
X-Cache: MISS from my.corp.cache
Proxy-Connection: keep-alive
Any idea why this is happening and how to solve it
Thanks,
Arnebjarne

Error in HttpWebRequest when using authentication in proxy environment
JezPop
WHat i need to see is the exact response with \r \n
Or you could send the trace to me. d g o rti @@@@@@ mi cro so ft ........ com
vaioks
It is very unliekly and not possible for us to send
a authorization header without actually receiving what the auth the server requires.
So I don't particularly buy the argument that we are sending before the server asks for auth.
Can you send us a system.net.trace file see http://blogs.msdn.com/dgorti for details
drewdb
in correct or not in the strict RFC format. Could you paste the
ethereal snapshot of the EXACT response status line
K Sumeet
The exception:
System.Net.WebException: The server committed a protocol violation. Section=ResponseStatusLine