0

On .net core while trying load my url to XMLDocument i getting that 500 Internal Server Error. While i get datas from same url with HTTPWebRequest it was have same error but after i add

request.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

That line it was solved my problem. But now i trying get datas with XML But getting that error again. How can i solve it ? Thanks for replies! My codes for XMLDocument :

string url = "https://www.antalyaeo.org.tr/tr/nobetci-eczaneler";
            var xml = new XmlDocument(); 

            xml.Load(url);
Rand Random
  • 7,300
  • 10
  • 40
  • 88
Uğurcan Uçar
  • 127
  • 1
  • 11
  • Download the file and pass the local file to XmlDocument? - eg. https://stackoverflow.com/questions/14192993 – Rand Random Jul 22 '21 at 14:39
  • @RandRandom i must get datas from url brother. So i cant download and pass it. – Uğurcan Uçar Jul 22 '21 at 14:41
  • Can you provide more detail about your error? try adding a try-catch block and see more detail. – MRP Jul 22 '21 at 15:22
  • As far as I know, the XmlDocument.Load method doesn't contains the property which support modify the Header. The only way is you firstly make request to the target url and then load the response stream in the XML document. Details, you could refer to this [answer](https://stackoverflow.com/a/7789235/7609093). – Brando Zhang Jul 23 '21 at 05:16
  • Rand Randoms response seems like the way to go. You're still pulling the xml 'fresh' from that url and you get the chance to insert the header you need to avoid the url giving a 500 response instead of the xml you're looking for. – JustAnotherDev Jul 23 '21 at 11:14

0 Answers0