473,372 Members | 1,074 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,372 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 9093
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.