473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 9096
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Justin Malloy | last post by:
I am using the System.Net.Webclient to try and download an XML file from a website but am receiving a HTTP protocol error when running the DownloadFile() sub routine. I did a HTTP trace using...
2
by: Rajiv | last post by:
Hello, I developed a No touch deployment client which accesses data through a web service. The application worked really well until I installed .NET framework 1.1 SP1. It worked well without the...
0
by: Dan W. | last post by:
Does anyone have any experience with this problem. I am trying to post about 20 fields of information to another server using System.Net.WebClient.UploadData. This works fine for some servers but...
1
by: pmclinn | last post by:
I keep getting the following error: The underlying connection was closed: The server committed an HTTP protocol violation. I have tried putting the <configuration> <system.net> <settings>...
1
by: Dan W. | last post by:
Does anyone have any experience with this problem. I am trying to post about 20 fields of information to another server using System.Net.WebClient.UploadData. This works fine for some servers but...
7
by: Tom | last post by:
Hello all: I have a method that does a POST to a secured website using HttpWebRequest. It worked when logging in the site, but it failed with an HTTP prococol violation error when it is used to...
1
by: Khadim | last post by:
I m using HTTWebResponse which is running smoothly on my system which is behing a proxy server. When I run the application with Live IP it gives "HTTP Protocol violation error" I can't use...
3
by: Rahul Anand | last post by:
As per our requirements we have a web service which internally connects (Simple HTTP Post Request) to a remote server to initiate some work. We are calling the web service method asynchronously...
0
by: oriol.ardevol | last post by:
Hi, I have an asp.net application that connects through an HttpWebRequest object to a ISAPI dll in a server. This isapi dll has some different method calls. What I do is calling the different...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

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.