HTML 抓取:请求的表单身份验证失败。提供的门票已过期

发布于 2024-09-17 17:08:26 字数 1218 浏览 6 评论 0原文

我们用作 DotNetNuke 系统一部分的 ActiveForums 模块在其 RSS feed 的 XML 中存在错误。它没有正确编码&符号,它将它们保留为 & 而不是将它们编码为 &

我已向公司报告了该错误,但在同时我需要修复。因此,我所做的就是创建一个中间页面,该页面通过 System.Net.HttpWebRequest.Create(url) 向 RSS feed 发出请求,然后执行 Regex.Replace code> 替换任何未编码的 & 符号。

问题是,当我在生产服务器上运行代码时,出现异常:远程服务器返回错误:(500)内部服务器错误。

我能想到的唯一原因是身份验证(由于服务器需要 NTLM),但据我所知,我正确地执行了这部分操作。我的代码如下所示:

string html = string.Empty;
string url = "http://intranet.nt.avs/dnn/Default.aspx?tabid=130";

WebResponse response;
WebRequest request = System.Net.HttpWebRequest.Create(url);

request.PreAuthenticate = true;
request.Credentials = System.Net.CredentialCache.DefaultCredentials;

response = request.GetResponse();

using (StreamReader sr = new StreamReader(response.GetResponseStream()) )
{
html = sr.ReadToEnd();
}

// Clean invalid XML
html = Regex.Replace( html, "&(?!amp;|gt;|lt;|quot;|apos;)", "&", RegexOptions.Multiline | RegexOptions.IgnoreCase );

Response.ContentType = "text/xml";
Response.Write( html );

更新:事件日志内容如下
错误代码:4005
事件消息:请求的表单身份验证失败。原因:提供的票已过期

The ActiveForums module we're using as part of our DotNetNuke system has a bug in the XML for it's RSS feed. It doesn't correctly encode ampersands, it leaves them as & rather than encoding them as &

I've reported the bug to the company, but in the mean time I need a fix. So what I've done is create an intermediary page that makes a request to the RSS feed via a System.Net.HttpWebRequest.Create(url) and them performs a Regex.Replace to replaces any unencoded ampersands.

The problem is that when I run the code on our production server I get an exception: The remote server returned an error: (500) Internal Server Error.

The only reason I could think of was around authentication (As the server requires NTLM), however as far as I can tell I'm doing this part of it correctly. My code is shown below:

string html = string.Empty;
string url = "http://intranet.nt.avs/dnn/Default.aspx?tabid=130";

WebResponse response;
WebRequest request = System.Net.HttpWebRequest.Create(url);

request.PreAuthenticate = true;
request.Credentials = System.Net.CredentialCache.DefaultCredentials;

response = request.GetResponse();

using (StreamReader sr = new StreamReader(response.GetResponseStream()) )
{
html = sr.ReadToEnd();
}

// Clean invalid XML
html = Regex.Replace( html, "&(?!amp;|gt;|lt;|quot;|apos;)", "&", RegexOptions.Multiline | RegexOptions.IgnoreCase );

Response.ContentType = "text/xml";
Response.Write( html );

Updated: Here's what the event log says
Error code: 4005
Event message: Forms authentication failed for the request. Reason: The ticket supplied has expired

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文