热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何查看HttpWebRequest发送的标头-HowtoviewtheheaderssentbyHttpWebRequest

ImscrapingasitewithHttpWebRequest,butthesiteisreturninganerror.Thepageworksfinewhe

I'm scraping a site with HttpWebRequest, but the site is returning an error. The page works fine when I hit it from my browser. I'd like to compare them to see what may be causing the error. I know how to intercept the request from my browser to inspect the headers, but how do I view the data sent by HttpWebRequest?

我正在使用HttpWebRequest抓取一个站点,但该站点返回错误。当我从浏览器点击它时页面工作正常。我想比较它们,看看可能导致错误的原因。我知道如何拦截来自浏览器的请求以检查标头,但是如何查看HttpWebRequest发送的数据?

5 个解决方案

#1


In order to compare what you do in code, and what the browser does, I am sure a HTTP debugging tool such as Fiddler, would be the easiest solution.

为了比较你在代码中所做的事情以及浏览器的作用,我确信像Fiddler这样的HTTP调试工具将是最简单的解决方案。

Fiddler acts as a proxy between client and server, and displays all information sent over the HTTP protocol.

Fiddler充当客户端和服务器之间的代理,并显示通过HTTP协议发送的所有信息。

It is possible that you will need to configure your .NET app to use the proxy that Fiddler provides. This blog post provides details on the subject.

您可能需要配置.NET应用程序以使用Fiddler提供的代理。此博客文章提供有关该主题的详细信息。

#2


http://www.fiddler2.com/fiddler2/ is a great tool for such things.

http://www.fiddler2.com/fiddler2/是一个很好的工具。

#3


The Net panel of Firebug will show all requests, including headers.

Firebug的Net面板将显示所有请求,包括标题。

EDIT: Saw you already knew how to do it in a browser as soon as I posted. Try the Headers property:

编辑:看到你发布后你已经知道如何在浏览器中做到这一点。尝试Headers属性:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.stackoverflow.com");
request.Method = "GET";
HttpWebResponse respOnse= (HttpWebResponse) request.GetResponse();
Console.WriteLine(response.Headers);

#4


You can get the headers from a HTTPWebRequest via the Headers property. From MSDN: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.headers.aspx

您可以通过Headers属性从HTTPWebRequest获取标头。来自MSDN:http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.headers.aspx

#5


I don't know if there's a general solution. But if you're using Firefox, either of two add-ons will help: Firebug, or LiveHTTPHeaders.

我不知道是否有一般解决方案。但是如果你使用的是Firefox,那么两个附加组件中的任何一个都会有所帮助:Firebug或LiveHTTPHeaders。


推荐阅读
author-avatar
手机用户2502857335
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有