Hi there,
I am getting RSS feeds from a URL using HTTPClient, after all codes are written and I test on localhost, RSS feeds gets fetched but after I publish to the server, I get this error.
One or more errors occurred. at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task`1.get_Result() at dayrunnerapp.Controllers.HomeController.callRss(String url)
Here's what I have tried.
What I have tried:
this is the controller view
public ActionResult News()
{
try
{
var url = "http://www.inboundlogistics.com/cms/rss-feed";
string html = string.Empty;
html = callRss(url);
XDocument xml = XDocument.Parse(html);
var RSSFeedData = (from x in xml.Descendants("item")
select new FeedObjects
{
Title = ((string)x.Element("title")),
Link = ((string)x.Element("link")),
test = ((string)x.Element("description").Value),
Description = ((string)x.Element("description").Value.Replace("/cms//", "http://").Replace(")", "")),
Date = ((string)x.Element("pubDate"))
});
ViewBag.RSSFeed = RSSFeedData;
ViewBag.URL = url;
}
catch (Exception e)
{
ViewBag.Error = e.Message+"\n\r"+e.StackTrace;
Console.WriteLine(e.Message);
}
return View();
}
this is the callRss function
[HttpGet, AllowCrossSiteJson]
private string callRss(string url)
{
string html = String.Empty;
cli = new HttpClient();
cli.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
cli.Timeout = TimeSpan.FromMilliseconds(100000);
try
{
HttpResponseMessage result = cli.GetAsync(url).Result;
html = Encoding.UTF8.GetString(result.Content.ReadAsByteArrayAsync().Result);
}
catch (Exception ex)
{
html = ex.Message +"\n\r"+ ex.StackTrace;
}
return html;
}
This works perfectly fine on localhost, without changing anything, I publish and deploy but I get the above mentioned error when I run the URL on the server. Please what haven't I put into consideration yet?