472,103 Members | 1,048 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,103 software developers and data experts.

Getting error 'The underlying connection was closed: The server committed an HTTP protocol violation'

Hi all,

I am having application where i am downloading xml content using
webrequest. my code is as below
HttpWebRequest lWebRequest = (HttpWebRequest) WebRequest.Create(URL);
HttpWebResponse lWebResponse = (HttpWebResponse)
lWebRequest.GetResponse();
StreamReader lResponseStream = new
StreamReader(lWebResponse.GetResponseStream(),enc) ;
Data = lResponseStream.ReadToEnd();
lWebRequest = null;
lWebResponse.Close();
IResponseStream.Close();

Here i am getting rss feeds using webrequest. Then i am loding rss
that is data using xmldocument.load.

when i am trying to change node of rss using replacechild method i am
getting error mention in subject line.

I am not getting why it is happening as i am not doing any operation
with httpwebrequest.

Can anyone shed some light on it.

Please do help me.

thanks in advance.

May 7 '07 #1
5 8917
Archana wrote:
I am having application where i am downloading xml content using
webrequest. my code is as below
HttpWebRequest lWebRequest = (HttpWebRequest) WebRequest.Create(URL);
HttpWebResponse lWebResponse = (HttpWebResponse)
lWebRequest.GetResponse();
StreamReader lResponseStream = new
StreamReader(lWebResponse.GetResponseStream(),enc) ;
Data = lResponseStream.ReadToEnd();
lWebRequest = null;
lWebResponse.Close();
IResponseStream.Close();

Here i am getting rss feeds using webrequest. Then i am loding rss
that is data using xmldocument.load.
Why don't you simply use the Load method with the URL e.g.
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(URL);
Usually there is no need to use HttpWebRequest/HttpWebResponse if all
you want to do is load XML from a URL.

And if Data above is a string then you do not need the Load method, in
that case you would need LoadXml e.g.
xmlDocument.LoadXml(Data);
when i am trying to change node of rss using replacechild method i am
getting error mention in subject line.

I am not getting why it is happening as i am not doing any operation
with httpwebrequest.
That sounds indeed odd. Can you show us the URL you load and exactly the
code which throws the error?
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 7 '07 #2
Hi thanks for your reply.

Let me elaborate my point more clearly.

i have one xml file which us using one dtd file which is on another
web site.

so when i get content of that xml using xmldocument and try to change
innerxml of any node i am getting above error,

my question is if i am updating any node of xml and that new node is
not in dtd file then will it cause any problem.

and every time when i am updating any node will dtd file gets loaded?

please help me asap.

thanks in advance.
May 7 '07 #3
Archana wrote:
i have one xml file which us using one dtd file which is on another
web site.

so when i get content of that xml using xmldocument and try to change
innerxml of any node i am getting above error,
You can try to add a custom resolver by setting the XmlResolver property
as needed:
<http://msdn2.microsoft.com/en-us/library/system.xml.xmldocument.xmlresolver.aspx>
That way you can load the DTD from a local cache instead of from the
HTTP server.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 7 '07 #4
hi,

thanks for your reply.

can you tell me every time when i use innerxml will it try to load dtd
file. because in stack trace i am getting following:-

at System.Net.HttpWebRequest.CheckFinalStatus()\r\n at
System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)\r
\n at System.Net.HttpWebRequest.GetResponse()\r\n at
System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials
credentials)\r\n at System.Xml.XmlDownloadManager.GetStream(Uri uri,
ICredentials credentials)\r\n at
System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type
ofObjectToReturn)\r\n at
System.Xml.Schema.DtdParser.ParseDocTypeDecl()\r\n at
System.Xml.Schema.DtdParser.Parse()\r\n at
System.Xml.XmlValidatingReader.UpdatePartialConten tDTDHandling()\r\n
at System.Xml.XmlValidatingReader.ReadWithCollectText Token()\r\n at
System.Xml.XmlValidatingReader.Read()\r\n at
System.Xml.XmlLoader.LoadChildren(XmlNode parent)\r\n at
System.Xml.XmlLoader.ParsePartialContent(XmlNode parentNode, String
innerxmltext, XmlNodeType nt)\r\n

at System.Xml.XmlLoader.LoadInnerXmlElement(XmlElemen t node, String
innerxmltext)\r\n

at System.Xml.XmlElement.set_InnerXml(String value)\r\n

from above trace you can see then set_innerxml calls
httpwebreaquest.getresponse.

i don't know why it is happening as my xml file is local file but dtd
file is on some other site.

can you help me.

thanks .

May 7 '07 #5
See this:
http://www.janinedalton.com/blog/arc...col-violation/

From the article:

This error started springing up after .NET Framework 1.1 SP1 was released.
To enhance security, this error will be raised on fetching from a web site if
the server’s HTTP headers obey certain rules e.g. there cannot be a space in
the header name. The problem is that some websites do not conform.
To avoid errors on trying to fetch from these sites, you can add the
following to your web.config file:

<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>

If you have a batch file or console application that is affected, you can
resolve the issue by making a file called yourapp.exe.config (where yourapp
is the name of your executable) containing the above code. You may need to
precede this with the line:

<?xml version=”1.0″ encoding=”utf-8″ ?>
May 18 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Justin Malloy | last post: by
1 post views Thread by Khadim | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.