我从校内截下了登录框<form method="post" id="loginForm" class="login-form" action=" http://login.renren.com/Login.do" >
    <p class="top">
    <label for="email">账号:</label>
    <input type="text" name="email"  class="input-text" value="" id="email" tabindex="1" />
    </p>
    <p>
    <label for="password">密码:</label>
    <input type="password" id="password" name="password"  class="input-text" tabindex="2" value="" />
    </p>
    <p>
    <label for="autoLogin" class="labelCheckbox"><input type="checkbox" name="autoLogin" id="autoLogin" value="true" tabindex="3" />下次自动登录</label>
    </p>
    <p>
    <input type="hidden" name="origURL" value=" http://www.renren.com/SysHome.do" />
    <input type="submit" id="login"  class="input-submit" value="登录" tabindex="4"  />
    <a href=" http://renren.com/GetPasswd.do">找回密码</a>
    </p>
</form> 保存成一个文件,用HttpWEbRequest,或HttpWebResponse怎么登录呢。

解决方案 »

  1.   

      去看看CSDN小助手吧,源代码里面有你想要的。   
        
      ===============================   
      http://qqwwee.com/csdn.rar   
      CSDN小助手
      

  2.   

                string strPostData = String.Format("__EVENTTARGET=txtEmail&__EVENTARGUMENT=&__LASTFOCUS=&__VIEWSTATE={0}&txtEmail={1}&txtPassword={2}&btnLogin=%E7%99%BB%E5%BD%95&__EVENTVALIDATION={3}"
                                                    , this.__VIEWSTATE
                                                    , "[email protected]"
                                                    , "111111"
                                                    , this.__EVENTVALIDATION
                                                    );
                strHTML = wFunc.GetHTML("http://ffxxxxx.ffff.com/Ufffar/Acaaaas/login1.aspx", strPostData, System.Text.Encoding.UTF8);
                string strAlert = RegexFunc.GetMatch(strHTML, "alert\\(\"(.*)\"\\)");
                if (strAlert.Length == 0)
                {
                    strAlert = RegexFunc.GetMatch(strHTML, "alert\\(\'(.*)\'\\)");
                }
                if (strAlert.Length != 0)
                {
                    MsgFunc.ShowWarning(strAlert);            }            try
                {
                    WebUser login = new WebUser();
                    login.Name = this.UserName;
                    login.Cookies = wFunc.Cookies;
                    //login.ReqCookies = wFunc.ReqCookies;                Variant.CurrentUser = login;
                }
                catch
                {
                    Variant.CurrentUser = null;                return;
                }这是其中的代码
      

  3.   


    拿这个有什么用?你要去看点登录的时候HTTP的请求和响应过程,那才有用
      

  4.   

    HttpWebResponse得到后,怎么提交?
      

  5.   

    我用ruby做的校内网(现在改叫人人了)相册下载器
    你好好研究研究吧require "YAML"
    require 'open-uri'
    require 'net/http'
    require 'CGI'
    require "ftools"
    def get_html(url)
     open(url,"Cookie" => "kl=#{@kl}"){|http|
      html = http.read
     }
    end
    def init_config
     xiaonei_config = "xiaonei.yml"
     if !File.exist?(xiaonei_config)
      xn = {'password' => "",'user' => "" }
      File.open(xiaonei_config,'w') {|f| f.write(xn.to_yaml) }
     end
     xn = YAML.load_file(xiaonei_config)
     @email = xn['user']
     @password = xn['password']
     p "input your email(#{@email}):"
     $_ = STDIN.gets.strip
     @email = $_ || @email if !$_.empty?
     #p @email
     xn['user'] = @email
     p "input your password(#{@password}):"
     $_ = STDIN.gets.strip
     @password = $_ || @password if !$_.empty?
     #p @password
     xn['password'] = @password
     #p xn.inspect
     File.open(xiaonei_config,'w') {|f| f.write(xn.to_yaml) }
    end
    def login_xiaonei
     init_config
     params ={}
     params["email"] = @email
     params["password"] = @password
     uri=URI.parse("http://www.renren.com/Login.do")
     res = Net::HTTP.post_form(uri,params) 
     @cookies = CGI::Cookie::parse(res.header['set-cookie']) #返回的cookie情况
     @kl = @cookies["kl"][1]
    end
    def save_photo
     p "input the url of the album:(input \"q\" to quit)"
     
     while 1
      @album_url = STDIN.gets.strip
      break unless @album_url != 'q'
      if @album_url =~ /getalbum.do\?id=(\d+)\&/
       @albumid = $1
       File.makedirs(@albumid)
       html = get_html(@album_url)
       f = File.new("test.html","w+") 
       f.puts(html)
       f.close
       if html =~ /.*(http:\/\/photo.renren.com\/getphoto.do\?id=(.*?)\&owner=.*?\&curpage=).*/
        first_photo_page_url = $1
        @first_photoid = $2
        @down_count = 0
        down_photo(first_photo_page_url)
       else
        p "album url error"
       end
      else
       p "error album url "
      end
     end
    end
    def down_photo(url)
     p "---------------start to down photos---------------"
     while @down_count < 2000
      if url =~ /id=(\d*?)&/
       photoid = $1
       break if @down_count >0 and photoid == @first_photoid
      end 
      
      html = get_html(url)
      if html =~ /.*id=\"photo\"\s*?src=\"(http:\/\/.*?.xnimg.cn\/.*?(large.*?\.???))\".*/
       #p $1
       data = open(URI::encode($1)){|f| f.read}  
       file = File.new "#{@albumid}/#{$2}", 'w+' 
       file.binmode   
       file << data 
       file.flush  
       file.close 
       p "get a picture #{$2}"
      else
       break
      end
      if html =~ /id=\"next\" href=\"(.*?)\"/
       url = $1
      else
       break
      end
      @down_count += 1
     end
     p "--------------------end---------------"
     p "you have down #{@down_count} photos"
    end
    def main
     
     if login_xiaonei
      p "login success!"
      save_photo
     else
      p "login failure"
     end
    endmain
      

  6.   

    一般大的网站对那个都是有检测的。。判断你的操作是来自哪里。如:        /// 得到当前完整主机头
            /// </summary>
            /// <returns></returns>
            public static string GetCurrentFullHost()
            {
                HttpRequest request = System.Web.HttpContext.Current.Request;
                if (!request.Url.IsDefaultPort)
                {
                    return string.Format("{0}:{1}", request.Url.Host, request.Url.Port.ToString());
                }
                return request.Url.Host;
            }        /// <summary>
            /// 得到主机头
            /// </summary>
            /// <returns></returns>
            public static string GetHost()
            {
                return HttpContext.Current.Request.Url.Host;
            }
            /// <summary>
            /// 获取当前请求的原始 URL(URL 中域信息之后的部分,包括查询字符串(如果存在))
            /// </summary>
            /// <returns>原始 URL</returns>
            public static string GetRawUrl()
            {
                return HttpContext.Current.Request.RawUrl;
            }        /// <summary>
            /// 判断当前访问是否来自浏览器软件
            /// </summary>
            /// <returns>当前访问是否来自浏览器软件</returns>
            public static bool IsBrowserGet()
            {
                string[] BrowserName = { "ie", "opera", "netscape", "mozilla" };
                string curBrowser = HttpContext.Current.Request.Browser.Type.ToLower();
                for (int i = 0; i < BrowserName.Length; i++)
                {
                    if (curBrowser.IndexOf(BrowserName[i]) >= 0)
                    {
                        return true;
                    }
                }
                return false;
            }        /// <summary>
            /// 判断是否来自搜索引擎链接
            /// </summary>
            /// <returns>是否来自搜索引擎链接</returns>
            public static bool IsSearchEnginesGet()
            {
                string[] SearchEngine = { "google", "yahoo", "msn", "baidu", "sogou", "sohu", "sina", "163", "lycos", "tom" };
                string tmpReferrer = HttpContext.Current.Request.UrlReferrer.ToString().ToLower();
                for (int i = 0; i < SearchEngine.Length; i++)
                {
                    if (tmpReferrer.IndexOf(SearchEngine[i]) >= 0)
                    {
                        return true;
                    }
                }
                return false;
            }        /// <summary>
            /// 获得当前完整Url地址
            /// </summary>
            /// <returns>当前完整Url地址</returns>
            public static string GetUrl()
            {
                return HttpContext.Current.Request.Url.ToString();
            }你的想法是好。。但是。这种操作完全可以防范。。研究是行。