简体   繁体   English

如何使用WebRequest仅下载标题

[英]How to download only the headers with WebRequest

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. 我正在编写一些脚本来查找ASP.NET中填充oracle漏洞的漏洞,为此我需要查看响应中的HttpStatusCode。 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. 唯一的问题是下载了整个响应正文(根据Fiddler),这对大量枚举有一些性能影响。 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. 也许我没有正确地理解一些基本的HTTP概念,但是如果有一种方法可以通过在Web上拉下完整的页面来显着减少响应大小并消除响应时间的某些变化,我很想听听它。 Thanks! 谢谢!

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

This other stack overflow question has the detailed answer with a code example: 这个其他堆栈溢出问题有一个带有代码示例的详细答案:

WebRequest "HEAD" light weight alternative WebRequest“ HEAD”轻量级替代

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM