Answer the question
In order to leave comments, you need to log in
There is no page, but the server returns "200", how to understand in this situation that the page is still missing?
For example, with this url: https://XN--80APMGLWL.XN--P1AI/in/Moscow/Mebelnaya_...
In fact, there are only 21 pages. The rest are displayed empty.
How in this situation to understand that the page still does not exist?
using System;
using System.Net;
namespace ResponseTest
{
class Program
{
static void Main(string[] args)
{
string url = "https://XN--80APMGLWL.XN--P1AI/в/Москва/Мебельная_фурнитура/стр_210";
int statusCode;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
request.Method = WebRequestMethods.Http.Head;
request.Accept = @"*/*";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
statusCode = (int)response.StatusCode;
response.Close();
}
catch (WebException ex)
{
if (ex.Response == null)
throw;
statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
}
Console.WriteLine(url);
Console.WriteLine(statusCode);
Console.ReadKey();
}
}
}
Answer the question
In order to leave comments, you need to log in
there is a page ... why is it not there?
if you specify
then there really is no page, and (for this site) statusCode
there will be a 302 (redirect to https://office.rf/404.htm )
1) change request.Method from HEAD to GET
2) full code:
string url = "https://XN--80APMGLWL.XN--P1AI/в/Москва/Мебельная_фурнитура/стр_11210";
int statusCode;
string html;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
request.Method = WebRequestMethods.Http.Get;
request.Accept = @"*/*";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
statusCode = (int)response.StatusCode;
using (StreamReader stream = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
html = stream.ReadToEnd();
}
response.Close();
if(!html.Contains("card")) Console.WriteLine("страницы не существует");
else Console.WriteLine("страница существует!");
}
catch (WebException ex)
{
if (ex.Response == null)
throw;
statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
}
//Console.WriteLine(url);
//Console.WriteLine(statusCode);
Console.ReadKey();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question