HttpWebRequest POST data

梦想的初衷 提交于 2019-12-23 03:04:22

问题


Is it possible to make an exact identical POST with HttpWebRequest in C# as a browser would? Without a page being able to detect that it is actually no browser?

If so, were could i read up more on that?


回答1:


Download and become familiar with a tool like Fiddler. It allows you to inspect web requests made from applications, like a normal browser, and see exactly what is being sent. You can then emulate the data being sent with a request created in C#, providing values for headers, cookies, etc.




回答2:


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.

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#?
Is WebRequest The Right C# Tool For Interacting With Websites?
http://codehelp.smartdev.eu/2009/05/08/improve-webclient-by-adding-useragent-and-cookies-to-your-requests/



来源:https://stackoverflow.com/questions/10541270/httpwebrequest-post-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!