Error: The remote server returned an error: (400) Bad Request for fetch and display Rss feeds in ASP.Net

Last Reply 9 months ago By vaibhavN

Posted 9 months ago

Gm Sir,

http://www.aspsnippets.com/Articles/Fetch-and-Display-RSS-Feeds-using-ASP.Net.aspx

i m trying to use this bt i got error like:

 

The remote server returned an error: (400) Bad Request.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.

Source Error:


Line 50: catch(Exception ex)
Line 51: {
Line 52: throw ex;
Line 53: }
Line 54: }

;;

pls help me out sir..

Posted 9 months ago

Hi vaibhavN,

Please refer with below code and check

protected void Page_Load(object sender, EventArgs e)
{
    GetRSS();
}

private void GetRSS()
{
    //Create a WebRequest
    WebRequest rssReq = WebRequest.Create("http://www.asp.net/rss/content");

    //Set the timeout in Seconds for the WebRequest
    rssReq.Timeout = 5000;
    try
    {
        //Get the WebResponse 
        WebResponse rep = rssReq.GetResponse();

        //Read the Response in a XMLTextReader
        XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());

        //Create a new DataSet
        DataSet ds = new DataSet();

        //Read the Response into the DataSet
        ds.ReadXml(xtr);

        //Bind the Results to the Repeater
        rssRepeater.DataSource = ds.Tables[2];
        rssRepeater.DataBind();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    GetRSS()
End Sub

Private Sub GetRSS()
    'Create a WebRequest 
    Dim rssReq As WebRequest = WebRequest.Create("http://www.asp.net/rss/content")

    'Set the timeout in Seconds for the WebRequest 
    rssReq.Timeout = 5000
    Try
        'Get the WebResponse 
        Dim rep As WebResponse = rssReq.GetResponse()

        'Read the Response in a XMLTextReader 
        Dim xtr As New XmlTextReader(rep.GetResponseStream())

        'Create a new DataSet 
        Dim ds As New DataSet()

        'Read the Response into the DataSet 
        ds.ReadXml(xtr)

        'Bind the Results to the Repeater 
        rssRepeater.DataSource = ds.Tables(2)
        rssRepeater.DataBind()
    Catch ex As Exception
        Throw ex
    End Try
End Sub

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html