如何使用 WebRequest 仅下载标头

发布于 2024-09-25 08:30:09 字数 584 浏览 3 评论 0原文

我正在编写一些脚本来查找 ASP.NET 中 padding oracle 漏洞利用的漏洞,为此我需要查看响应中的 HttpStatusCode。我在大量具有不同场景的网站上执行此操作,性能很重要。我可以使用以下代码很好地做到这一点:

var req = (HttpWebRequest)WebRequest.Create(uri);
req.AllowAutoRedirect = false;
HttpWebResponse resp;

try
{
  resp = (HttpWebResponse)req.GetResponse();
  resp.Close();
}
catch (WebException e)
{
  resp = (HttpWebResponse)e.Response;
}
responseCode = resp.StatusCode;

唯一的问题是下载整个响应正文(根据 Fiddler),这对大量枚举有一点性能影响。所以问题是这样的;是否可以只检索标题而不下载整个正文?

也许我没有正确掌握一些基本的 HTTP 概念,但如果有一种方法可以通过在网络上拉取完整的页面来显着减少响应大小并消除响应时间的一些变化,我很想听听它。谢谢!

I’m writing some scripts to look for vulnerabilities to the padding oracle exploit in ASP.NET for which I need to look at the HttpStatusCode in the response. I’m doing this across a large number of my sites with different scenarios and performance is important. I can do this just fine with the following code:

var req = (HttpWebRequest)WebRequest.Create(uri);
req.AllowAutoRedirect = false;
HttpWebResponse resp;

try
{
  resp = (HttpWebResponse)req.GetResponse();
  resp.Close();
}
catch (WebException e)
{
  resp = (HttpWebResponse)e.Response;
}
responseCode = resp.StatusCode;

The only problem with this is that the entire response body is downloaded (according to Fiddler) which has a bit of a performance impact over a large number of enumerations. So the question is this; is it possible to retrieve just the headers without downloading the entire body?

Maybe I’m not grasping some fundamental HTTP concept properly, but if there’s a way to significantly cut down on the response size and take out some of the variability in response times by pulling complete pages down over the web, I’d love to hear it. Thanks!

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

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

发布评论

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

评论(2

时光病人 2024-10-02 08:30:09

也许在请求中使用 HEAD 动词?

Maybe use HEAD verb in request?

⊕婉儿 2024-10-02 08:30:09

这个其他堆栈溢出问题通过代码示例提供了详细答案:

WebRequest“HEAD”轻量级替代方案< /a>

This other stack overflow question has the detailed answer with a code example:

WebRequest "HEAD" light weight alternative

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