简体   繁体   English

HttpWebRequest POST数据

[英]HttpWebRequest POST data

Is it possible to make an exact identical POST with HttpWebRequest in C# as a browser would? 是否可以在C#中使用HttpWebRequest与浏览器进行完全相同的POST? Without a page being able to detect that it is actually no browser? 没有页面能够检测到它实际上没有浏览器?

If so, were could i read up more on that? 如果是这样,我可以阅读更多内容吗?

Download and become familiar with a tool like Fiddler . 下载并熟悉像Fiddler这样的工具。 It allows you to inspect web requests made from applications, like a normal browser, and see exactly what is being sent. 它允许您检查从应用程序(如普通浏览器)发出的Web请求,并确切地查看正在发送的内容。 You can then emulate the data being sent with a request created in C#, providing values for headers, cookies, etc. 然后,您可以使用C#创建的请求模拟发送的数据,为标题,Cookie等提供值。

I think this is doable. 我认为这是可行的。

Browser detection is done based on a header in the request. 浏览器检测基于请求中的标头完成。 All you need to do is set that header. 您需要做的就是设置标题。 In HttpWebRequest we dont need to set the headers collection but rather the .UserAgent property. 在HttpWebRequest中,我们不需要设置头集合,而是设置.UserAgent属性。

Eg: 例如:

.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)";

There is quite a lot to user agents. 用户代理有很多。 Check this link for the complete list of User-Agents 检查链接以获取用户代理的完整列表

Useful Links: 有用的链接:

How to create a simple proxy in C#? 如何在C#中创建一个简单的代理?
Is WebRequest The Right C# Tool For Interacting With Websites? WebRequest是否是与网站交互的正确C#工具?
http://codehelp.smartdev.eu/2009/05/08/improve-webclient-by-adding-useragent-and-cookies-to-your-requests/ http://codehelp.smartdev.eu/2009/05/08/improve-webclient-by-adding-useragent-and-cookies-to-your-requests/

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

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