Have you encountered this problem? I am running code similar to the code of this previous question . When "/? Test & format = xml" is enabled in nUnitTest mode and in the URI, nUnit fails with IOException: "Unable to read data from transport connection: connection closed".
However, the Fiddler trace that was running at that time shows the same xml that I expected.
I recreated the request headers exactly (almost) as they are sent when they are sent through the browser.
Finally, if I stay from "/? Test & format = xml" from the URI, I get html, which I would expect otherwise.
SOURCE OF CODE:
public virtual bool Run()
{
var request = CreateRequest();
var response = GetResponse(request);
var responseString = ReadResponse(response);
this.SetResults(responseString);
return this.IsSuccessful;
}
protected internal virtual HttpWebRequest CreateRequest()
{
var address = TestConfig.Address;
var request = (HttpWebRequest)WebRequest.Create(address);
request.Accept = "*/*";
request.UseDefaultCredentials = true;
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
return request;
}
protected internal virtual HttpWebResponse GetResponse(HttpWebRequest request)
{
var response = (HttpWebResponse) request.GetResponse();
return response;
}
protected internal virtual string ReadResponse(HttpWebResponse response)
{
var stream = response.GetResponseStream();
var responseString = ReadResponse(stream);
stream.Close();
response.Close();
return responseString;
}
protected internal virtual string ReadResponse(Stream stream)
{
var reader = new StreamReader(stream);
var responseString = reader.ReadToEnd();
return responseString;
}