我将如何编程方式登录到网站,如CodeProject上或计算器,使用Web客户端? [英] How would I programatically login to a site such as codeproject or stackoverflow, using WebClient?
本文介绍了我将如何编程方式登录到网站,如CodeProject上或计算器,使用Web客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要登录到像从服务器计算器或CodeProject上的网站。
I want to login to a site like stackoverflow or codeproject from a server.
有没有办法登录到一个网站像这样使用 Web客户端
类?
Is there any way to login to a site such as this using the WebClient
class?
推荐答案
的 http://code.google.com/p/stackexchange-api/
- 使用Chrome开发者在Firefox工具或Firebug的看怎么有问题的帖子的网站的登录数据。
- 复制铬/ Firefox的节目表单数据。
- 创建一个
的HttpWebRequest
和表单数据写入request.GetRequestStream()
- 设置内容类型为
应用程序/ x-WWW窗体-urlencoded
- 呼叫
request.GetResponse()
。
- Use Chrome Developer tools or Firebug in Firefox to look how the website in question posts the login data.
- Copy the FORM data that chrome/firefox shows.
- Create a
HttpWebRequest
and write the FORM data torequest.GetRequestStream()
- Set content-type to
application/x-www-form-urlencoded
- Call
request.GetResponse()
.
请注意,您必须保持它的响应中指定,将它们复制到所有后续请求保持被记录所有的cookies。
Note that you got to keep all cookies which are specified in the response and copy them to all subsequent requests to keep being logged in.
这篇关于我将如何编程方式登录到网站,如CodeProject上或计算器,使用Web客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文