VS.NET 2010 (and above) Users Click Here   

HOMECONTACT PRODUCTS DOWNLOADS PURCHASE TESTIMONIALS FORUMS COMPANY CONTACT
Home
Products
Downloads
Purchase
Licensing
Licensing FAQ
Software Updates
Support Forums
Testimonials
Feature Requests
Guarantee
About Us
Contact Us
Hosting Companies
Privacy Policy
   
Shopping Cart



aspNetMHT: Unable to read data from the transport connection

by Dave 3. March 2011 07:39

Recently I had a customer email me, that they were getting the following exception being thrown from aspNetMHT. It was:

System.IO.IOException: Unable to read data from the transport connection: The connection was closed.
   at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)

This exception was happening when aspNetMHT was making a remote request to the webserver.

Basically, the remote webserver closing the connection.

To prevent this from happening, the following properties needed to be set:

            m.HttpProtocolVersion = HttpVersion.Version10
            m.HttpKeepAlive = false

Where "m" is the local MHT object. 

Here is a more complete, but short, code example:

C#

//any url we want to fetch, for example, google.com
string url ="http://www.google.com"; 
MHT m = new MHT();

//ignore any broken links
m.Ignore404 = true;

m.HttpProtocolVersion = HttpVersion.Version10;
m.HttpKeepAlive = false;
m.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
	
//enable logging for any troubleshooting purposes
m.Logger = new MHTLog("c:\\temp\\mht.log");
m.Logger.Overwrite = true;
m.Logger.Enabled = true;

m.LoadUrl(url);
m.Parse();

m.SaveToFile("c:\\temp\\");

VB.NET

 'any url we want to fetch, for example, google.com
Dim url As String = "http://www.google.com"
Dim m As New MHT()

'ignore any broken links
m.Ignore404 = True

m.HttpProtocolVersion = HttpVersion.Version10
m.HttpKeepAlive = False
m.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"

'enable logging for any troubleshooting purposes
m.Logger = New MHTLog("c:\temp\mht.log")
m.Logger.Overwrite = True
m.Logger.Enabled = True

m.LoadUrl(url)
m.Parse()

m.SaveToFile("c:\temp\")

As always, if anyone has any questions, feel free to contact me at the Contact Us page.
Dave Wanta

Comments are closed

 

 

Testimonial

Exactly what I was looking for. Thanks for the quick reply. "

J. Kayne | dailyshopper.com

Read more testimonials
ListNanny aspNetDNS aspNetEmail aspNetPOP3 aspNetMX IPMuncher aspNetMIME aspNetPING aspNetTraceRoute aspNetIMAP aspNetMHT