.Net Core 3.0 尝试从 url 获取 html 内容时此错误页面可能包含敏感错误
.Net Core 3.0 while trying take html content from url This error page might contain sensitive error
就像我说的,我试图从 URL 获取一些 HTML 内容,但它告诉我“此错误页面可能包含敏感错误”,我该如何解决?我的代码:
try
{
string siteContent = string.Empty;
string url = "https://www.antalyaeo.org.tr/tr/nobetci-eczaneler";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AutomaticDecompression = DecompressionMethods.GZip;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader streamReader = new StreamReader(responseStream))
{
siteContent = streamReader.ReadToEnd();
}
return siteContent;
}
catch (WebException webex)
{
WebResponse errResp = webex.Response;
using (Stream respStream = errResp.GetResponseStream())
{
StreamReader reader = new StreamReader(respStream);
string text = reader.ReadToEnd();
return text;
}
}
错误信息:
This error page might contain sensitive information because ASP.NET is
configured to show verbose error messages using <customErrors
mode="Off"/>. Consider using <customErrors mode="On"/> or
<customErrors mode="RemoteOnly"/> in production environments.-->
我尝试了什么:当我搜索 google 和 Whosebug 时,我看到他们说 make customError="False" 或者有点像 system.web / web.config文件在我的项目中。我该如何解决?谢谢
您需要添加user-agent
否则服务器似乎拒绝您的请求,例如:
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.AutomaticDecompression = DecompressionMethods.GZip;
request.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
就像我说的,我试图从 URL 获取一些 HTML 内容,但它告诉我“此错误页面可能包含敏感错误”,我该如何解决?我的代码:
try
{
string siteContent = string.Empty;
string url = "https://www.antalyaeo.org.tr/tr/nobetci-eczaneler";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.AutomaticDecompression = DecompressionMethods.GZip;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader streamReader = new StreamReader(responseStream))
{
siteContent = streamReader.ReadToEnd();
}
return siteContent;
}
catch (WebException webex)
{
WebResponse errResp = webex.Response;
using (Stream respStream = errResp.GetResponseStream())
{
StreamReader reader = new StreamReader(respStream);
string text = reader.ReadToEnd();
return text;
}
}
错误信息:
This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using <customErrors mode="Off"/>. Consider using <customErrors mode="On"/> or <customErrors mode="RemoteOnly"/> in production environments.-->
我尝试了什么:当我搜索 google 和 Whosebug 时,我看到他们说 make customError="False" 或者有点像 system.web / web.config文件在我的项目中。我该如何解决?谢谢
您需要添加user-agent
否则服务器似乎拒绝您的请求,例如:
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.AutomaticDecompression = DecompressionMethods.GZip;
request.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())