失控的 HTTPWebRequest

发布于 2024-08-18 00:22:14 字数 912 浏览 2 评论 0原文

我有一个用 C# 编写的浏览器帮助程序对象,当用户单击 Windows 窗体上的按钮时,它会向我的服务器发出 HTTPWebRequest POST,在正常情况下,这效果很好。然而,时不时地,我会遇到一个似乎发疯的 BHO,不断向我发送大量 HTTPWebRequest(每分钟大约 50 到 100 个)。我能够阻止客户端重新启动 PC 的行为的唯一方法是,用户通常甚至关闭了 IE,但 POST 不断出现。

有没有人在使用 HTTPWebRequest 时见过类似的行为?连接中的某些重试逻辑似乎变得疯狂,但我认为 HTTPWebRequest 没有内置任何重试机制,因此这似乎不太可能。

我的连接设置不正确,是否有好的策略来防止此类情况发生?

以下是我设置连接的方法:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(myUrl);
webRequest.Timeout = 30000;
webRequest.Method = "POST";
webRequest.KeepAlive = false;
System.Net.ServicePointManager.Expect100Continue = false;
webRequest.ContentType = "text/xml";
webRequest.ContentLength = myData.Length;

using (StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream()))
{
    requestWriter.Write(this.myData);
    requestWriter.Close();
}

I've got a Browser Helper Object written in C# that makes a HTTPWebRequest POST to my server when the user clicks a button on a windows form, and in the normal case this works great. However, every so often, I'll get a BHO that seems to go crazy and continually send me a huge number of HTTPWebRequests (around 50 to 100 per minute). The only way I've been able to stop the behavior to have the client reboot their PC, often the users have even closed IE, but the POSTs keep rolling in.

Has anyone ever seen a similar behavior when using HTTPWebRequest? It almost seems like some retry logic in the connection is going crazy, but I didn't think HTTPWebRequest had any retry mechanism built in, so that seems very unlikely.

I'm setting up my connection incorrectly and is there a good strategy for preventing something like this?

Here is how I'm setting up my connection:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(myUrl);
webRequest.Timeout = 30000;
webRequest.Method = "POST";
webRequest.KeepAlive = false;
System.Net.ServicePointManager.Expect100Continue = false;
webRequest.ContentType = "text/xml";
webRequest.ContentLength = myData.Length;

using (StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream()))
{
    requestWriter.Write(this.myData);
    requestWriter.Close();
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亚希 2024-08-25 00:22:14

发生这种情况时,您能让客户端从他的 PC 获取 Wireshark 跟踪吗?

是否有其他对象正在托管 IE 控件,从而导致您的 BHO 被托管并开始触发请求?

不幸的是,除非你能在你的机器上得到一个重现,否则它只是一个盲目的尝试。

Can you have the client get a wireshark trace from his PC when this happens?

Could there be some other object that is hosting the IE control, which in turn causes your BHO to be hosted and start triggering the requests?

Unfortunately, unless you can get a repro on your machine, it will just be a shot in the dark.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文