Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTPWebRequest.GetResponse() failing with authenticated requests through a transparent proxy
    primarykey
    data
    text
    <p>We're using the <code>HTTPWebRequest</code> objects to make HTTP requests to our application and we're having a problem when the request requires authentication and there is a transparent proxy (Squid 3.1.10).</p> <pre><code>string url = "http://www.icode.co.uk/test/auth.php"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Credentials = new NetworkCredential("username", "password"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); MessageBox.Show(reader.ReadToEnd()); reader.Close(); stream.Close(); response.Close(); </code></pre> <p>Our original code used the WebClient class which exhibited the same problem.</p> <p>The first time this code runs, it displays the result correctly. When the code runs a second time, it fails on the <code>GetResponse()</code> line with:</p> <pre><code>System.Net.WebException was unhandled Message="The server committed a protocol violation. Section=ResponseStatusLine" Source="System" StackTrace: at System.Net.HttpWebRequest.GetResponse() at Dummy.DummyForm.button1_Click(Object sender, EventArgs e) in H:\Trial\Dummy\DummyForm.cs:line 42 at ... </code></pre> <p>On Windows 7, restarting the process causes it to recover and work once, but Server 2003 requires a full reboot.</p> <p>Looking at the <a href="https://dl.dropboxusercontent.com/u/2931731/StackOverflow/10984264/failed.cap" rel="nofollow">network capture</a>, two requests are identical to start with, the initial unauthenticated request is sent and the server replies, but the failing requests sends the 2nd authenticated request in the middle of the initial reply as if it's ignoring the <code>Content-Length</code> header (which is correct). It then receives the rest of the initial reply and fails with the protocol error.</p> <p><img src="https://dl.dropboxusercontent.com/u/2931731/StackOverflow/10984264/failed.png" alt="Wireshark capture"></p> <p>It does seem odd that the client (<code>HTTPWebRequest</code>) doesn't close the connection cleanly though.</p> <p>When the proxy is not in use (non port 80 or internal traffic) the requests all work as expected. When there is no authentication, it also works as it only makes the single request.</p> <p>I've already reduced the problem code to the minimum and reproduced it with the MSDN sample, but does anyone know if this is a known issue or a problem in our (.NET or Squid) configuration?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload