HttpWebRequest 方法 HEAD 返回正文
我使用“Head”方法的网络请求不断返回我的网页正文(在本地主机上)。 下面是它的基本创建方式:
HttpWebRequest webrequest = WebRequest.Create(url.ToString()) as HttpWebRequest;
webrequest.Method = "HEAD";
WebResponse response = webrequest.GetResponse();
当我在 aspx.cs 页面中放置一个断点时,我进入 OnInit() 方法以及 Page_Load() 方法,我认为我不应该使用 Head 方法进入该方法请求(我错了吗?)。
在我的 Page_Load() 中,我执行了一些代码,当我使用 Head 方法调用时,我不希望执行这些代码,但稍后当我使用 Get 方法调用时(一旦获得标头),就会执行这些代码。
我错过了什么吗? (还不太熟悉 Http 请求和响应...:/) 感谢您的帮助!
My web request with the method "Head" keeps returning the body of my webpage (on localhost).
Here is how it is basically created:
HttpWebRequest webrequest = WebRequest.Create(url.ToString()) as HttpWebRequest;
webrequest.Method = "HEAD";
WebResponse response = webrequest.GetResponse();
As I put a breakpoint in my aspx.cs page, I step into the OnInit() method and also the Page_Load() method where I believe I'm not supposed to step in with a Head method request (am I wrong?).
In my Page_Load() I execute some code that I do not want to be executed when I call with the Head method, but later when I call with the Get method (once I got the headers).
Am I missing something? (not too familiar with Http requests and responses yet... :/)
Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这个示例代码方法......
希望它有帮助
http://forums.asp.net/t/1412824.aspx/1
Try this sample code approach ....
hope it helps
http://forums.asp.net/t/1412824.aspx/1
不同之处在于,如果您尝试读取响应,则在 HEAD 的情况下您什么也得不到。在哪里可以看到 GET 情况下的响应内容
The difference is, if you try to read the response you get nothing in case of HEAD. Where as you can see the response content in case of GET