我将如何编程方式登录到网站,如CodeProject上或计算器,使用Web客户端? [英] How would I programatically login to a site such as codeproject or stackoverflow, using WebClient?

查看:159
本文介绍了我将如何编程方式登录到网站,如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/


  1. 使用Chrome开发者在Firefox工具或Firebug的看怎么有问题的帖子的网站的登录数据。

  2. 复制铬/ Firefox的节目表单数据。

  3. 创建一个的HttpWebRequest 和表单数据写入 request.GetRequestStream()

  4. 设置内容类型为应用程序/ x-WWW窗体-urlencoded

  5. 呼叫 request.GetResponse()

  1. Use Chrome Developer tools or Firebug in Firefox to look how the website in question posts the login data.
  2. Copy the FORM data that chrome/firefox shows.
  3. Create a HttpWebRequest and write the FORM data to request.GetRequestStream()
  4. Set content-type to application/x-www-form-urlencoded
  5. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆