I have the following code:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Proxy.Credentials = CredentialCache.DefaultCredentials;
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream dataStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(dataStream))
{
string responseFromServer = reader.ReadToEnd();
System.Diagnostics.Debug.WriteLine(responseFromServer);
System.Diagnostics.Debug.WriteLine(response.StatusDescription);
}
- The service in question uses NTLM authentication.
- The URI above, pasted into Chrome returns expected results.
- Given the same Uri, this code works fine inside a console application.
- However, put into a a completely vanilla (i.e. straight from the template with a single action added to the controller) MVC application, it fails with a 504 error.
- If I turn Fiddler on to try and capture what's going on, it works inside the MVC application.
My guess is that Fiddler causes this to work because it overwrites the proxy with itself; however, my impression is that running the above code would behave the same as pasting the URI into a browser.
I'm also guessing that the timeout is actually a misnomer, and it's simply not negotiating with the server (although I have no way to validate that theory).
Given that using Fiddler changes the behaviour of the request, how can I debug this issue?
EDIT:
Following the advice of @Alex Seleznyov, I tried running Microsoft Message Analyser. It looks a lot like the issue is that, while running under the web application, the code is not first contacting our internal proxy, but via the console application it is.