Click here to Skip to main content
15,304,269 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
Hi,
I have a problem with reading RSS data.
my code is
string url = "http://wwww.test.com";
                XmlTextReader reader = new XmlTextReader(url);
                var xmlDocument = new XmlDocument();
                xmlDocument.Load(reader);


I got this error

System.Net.WebException was caught
  HResult=-2146233079
  Message=The remote server returned an error: (403) Forbidden.
  Source=System
  StackTrace:
       at System.Net.HttpWebRequest.GetResponse()
       at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
       at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
       at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
       at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
       at System.Threading.CompressedStack.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
       at System.Xml.XmlTextReaderImpl.OpenUrl()
       at System.Xml.XmlTextReaderImpl.Read()
       at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
       at System.Xml.XmlDocument.Load(XmlReader reader)
       at BatchJobshuntable.batchjobs.CompanyReviews.DynamicCompanies(Int32 cid, String url) in E:\29-10-2014 BatchjobCode\BatchJobshuntable\batchjobs\CompanyReviews.cs:line 75
  InnerException: 


I dont understand why its come.
Please help me
Thanks.
Posted
Updated 22-Oct-20 10:38am
Comments
DamithSL 26-Dec-14 0:04am
   
check your application running environment having access to given site or not.
if there is proxy server, no internet access, firewalls etc may preventing accessing this site via your application
NagaRaju Pesarlanka 26-Dec-14 0:09am
   
thanks for replied me,
2 days back also its working fine, now its not working,
no problem with internet and no firewall setting. Everything is good but I dont access the url.
DamithSL 26-Dec-14 0:13am
   
check the user who running your windows service has the internet access permissions
NagaRaju Pesarlanka 26-Dec-14 0:19am
   
I am using console application.
my all services run under administrator.
DamithSL 26-Dec-14 0:21am
   
when you run console application from visual studio you get the same error?
NagaRaju Pesarlanka 26-Dec-14 0:21am
   
yes.
NagaRaju Pesarlanka 26-Dec-14 0:21am
   
VS-2010
DamithSL 26-Dec-14 0:22am
   
go to bin folder and run it as administrator and check the error.
would you mind if i ask for actual rss url?
NagaRaju Pesarlanka 26-Dec-14 0:28am
   
I got the soluation.
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "MyRSSReader/1.0");

XmlReader readers = XmlReader.Create(webClient.OpenRead(url));
var xmlDocument = new XmlDocument();
xmlDocument.Load(readers);

1 solution

string url="http://www.test.com";
WebClient webClient = new WebClient();
                webClient.Headers.Add("user-agent", "MyRSSReader/1.0");

                XmlReader readers = XmlReader.Create(webClient.OpenRead(url));
                var xmlDocument = new XmlDocument();
                xmlDocument.Load(readers);
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900