R
Rob Snodgrass
I have been working on a solution where we pull content using the
WebRequest/WebResponse request HTTP content and store it in a string. For
some pages, I reliably get an IOException however the pages work perfectly
fine in web browsers and 3rd party utilities.
The following code isolates the problem:
String result = null;
WebResponse objResponse = null;
WebRequest objRequest = null;
objRequest =
System.Net.HttpWebRequest.Create("http://www.chemistry.org/portal/a/c/s/1/professionals.html");
objResponse = objRequest.GetResponse();
using (System.IO.StreamReader sr =
new System.IO.StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
}
Console.Write(result);
-------------------------------
Are there any recommendations for overcoming these issues? I always get the
following exception...
System.IO.IOException was unhandled
Message="Unable to read data from the transport connection: The connection
was closed."
Source="System"
StackTrace:
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32
size)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadToEnd()
at HTTPRequestTest.Program.Main(String[] args) in
C:\Projects\Test\HTTPRequestTest\HTTPRequestTest\Program.cs:line 24
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Thanks
Rob
WebRequest/WebResponse request HTTP content and store it in a string. For
some pages, I reliably get an IOException however the pages work perfectly
fine in web browsers and 3rd party utilities.
The following code isolates the problem:
String result = null;
WebResponse objResponse = null;
WebRequest objRequest = null;
objRequest =
System.Net.HttpWebRequest.Create("http://www.chemistry.org/portal/a/c/s/1/professionals.html");
objResponse = objRequest.GetResponse();
using (System.IO.StreamReader sr =
new System.IO.StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
}
Console.Write(result);
-------------------------------
Are there any recommendations for overcoming these issues? I always get the
following exception...
System.IO.IOException was unhandled
Message="Unable to read data from the transport connection: The connection
was closed."
Source="System"
StackTrace:
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32
size)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadToEnd()
at HTTPRequestTest.Program.Main(String[] args) in
C:\Projects\Test\HTTPRequestTest\HTTPRequestTest\Program.cs:line 24
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Thanks
Rob