locked
The remote server returned an error: (503) Server Unavailable Asp.Net RRS feed

  • Question

  • User-937748457 posted

    I am using the following code which give me issue for more of sites,(works for some site)

    WebRequest req = WebRequest.Create("url"); 
    StreamReader sr =new StreamReader(req.GetResponse().GetResponseStream());
     
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    string strLine;
    while ((strLine = sr.ReadLine()) != null) { // Ignore blank lines
    if (strLine.Length > 0) sb.Append(strLine); } sr.Close();
    lbl
    .Text= sb.ToString();

    Wednesday, June 12, 2013 3:46 AM

Answers

  • User-937748457 posted

    after a long time search on google i found a way which work for all

     WebClient client = new WebClient();

                // Add a user agent header in case the
                // requested URI contains a query.

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

                Stream data = client.OpenRead("anyurl");
           
                StreamReader reader = new StreamReader(data);
                string s = reader.ReadToEnd();
               // Console.WriteLine(s);
                data.Close();
                reader.Close();
               lbl.Text= s.ToString();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 13, 2013 3:49 AM

All replies

  • User-257383369 posted

    can you give list of sites for which it doen't work?

    Wednesday, June 12, 2013 3:58 AM
  • User-937748457 posted

    For any commercial sites it do not work..you can take any example like

    http://dubai.dubizzle.com/

    http://uae.souq.com/ae-en/

     etc etc

    Wednesday, June 12, 2013 4:01 AM
  • User-646145796 posted

    hi,

    I copy your code and try it with "http://www.contoso.com",it works well.

    take a look at the following link:

    http://msdn.microsoft.com/zh-cn/library/0aa3d588(v=vs.80).aspx

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/984b72ac-e366-41fc-932d-f85d255ba18a

    Hope it can help you

    Thursday, June 13, 2013 1:43 AM
  • User-937748457 posted

    after a long time search on google i found a way which work for all

     WebClient client = new WebClient();

                // Add a user agent header in case the
                // requested URI contains a query.

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

                Stream data = client.OpenRead("anyurl");
           
                StreamReader reader = new StreamReader(data);
                string s = reader.ReadToEnd();
               // Console.WriteLine(s);
                data.Close();
                reader.Close();
               lbl.Text= s.ToString();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 13, 2013 3:49 AM