public string login()
    {
        string m_Name = "";//用户名
        string m_Password = "";//密码
        string url = "http://login.taobao.com/member/login.jhtml";
        string indata = "action=Authenticator&CtrlVersion=1,0,0,7&event_submit_do_login=anything&fc=2&from=tb&gvfdcname=10&gvfdcre=687474703A2F2F7777772E74616F62616F2E636F6D2F&loginType=3&longLogin=-1&pstrong=2&style=default&support=000001&tid=XOR_1_000000000000000000000000000000_675843554D0B09747B737579&TPL_username="+m_Name+"&TPL_password="+m_Password+"&TPL_redirect_url=";
        return HttpRequestPost(url, indata);
    }
    public CookieContainer mycookie=new CookieContainer();
    string str = "";
    public string HttpRequestPost(string url, string indata)
    {
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = indata.Length;
        request.Method = "POST";
        request.Timeout = 3 * 60000;
        request.CookieContainer = mycookie;
        request.AllowAutoRedirect = true;
        request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
        request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */*";
        Stream requestStream = null;
        StreamWriter writer = null;
       
        requestStream = request.GetRequestStream();//获取请求数据流句柄
        writer = new StreamWriter(requestStream, Encoding.GetEncoding("gbk"));
        writer.Write(indata);//发送数据indata
        writer.Close();
        requestStream.Close();
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();        mycookie.Add(response.Cookies);
        Stream responseStream = null;
        StreamReader reader = null;
       
        responseStream = response.GetResponseStream();
        reader = new StreamReader(responseStream, Encoding.GetEncoding("gbk"));
        str = reader.ReadToEnd();
        reader.Close();
        responseStream.Close();
        response.Close();
        request.Abort();
        request = null;        return str;
    }求助 为什么每次执行 总会跳到登陆页面 貌似是登陆的时候没保存COOKIE  跪求解决方案!!

解决方案 »

  1.   

    不能吧,密码校验的时候是.net是在配置文件里指定验证的文件名必须是本地哪个文件的,不可能你直接一个URL就能登进去的。
      

  2.   

    用wpe抓包看看,密码应该是加密的,你直接而写肯定不行
      

  3.   

    public void alimamapost()
      {  CookieContainer cc = new CookieContainer();
      ASCIIEncoding encoding = new ASCIIEncoding();
      string postData = "action=MembersAction&event_submit_do_login=true&forward=&query_string=&[email protected]&originalLogpasswd=a8824766&_fmm.l._0.lo=c781f1ee5ab17dff12ff6019325688f2&dologin=";
        
      byte[] data = Encoding.GetEncoding("GB2312").GetBytes(postData);  HttpWebRequest myRequest =
      (HttpWebRequest)WebRequest.Create("http://www.alimama.com/membersvc/member/login.htm");  myRequest.CookieContainer = cc;
      myRequest.ContentType = "application/x-www-form-urlencoded";
      myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";
      myRequest.Referer = "http://www.alimama.com/membersvc/member/login.htm";
        
      myRequest.AllowAutoRedirect = true;
      myRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, */*";
      myRequest.ContentLength = data.Length;
      myRequest.Timeout = 10000;
      myRequest.Method = "POST";
        
      Stream newStream = myRequest.GetRequestStream();
      newStream.Write(data, 0, data.Length);
      newStream.Close();  HttpWebResponse oresponse;  try
      {
      oresponse = (HttpWebResponse)myRequest.GetResponse();
      }
      catch (WebException ex)
      {
      if (ex.Response != null)
      {
      oresponse = (HttpWebResponse)ex.Response;
      }
      else
      {
      throw ex;
      }
      }  Stream dataStream = oresponse.GetResponseStream();  try
      {
        
      StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("gb2312"));  string responseFromServer = reader.ReadToEnd();  reader.Close();
      dataStream.Close();
      oresponse.Close();
        
      }
      catch (Exception k1)
      {
      throw k1;
      }  myRequest =
      (HttpWebRequest)WebRequest.Create("http://www.alimama.com/membersvc/adzone/site.htm?addsite=true");
      myRequest.CookieContainer = cc;
      try
      {
      oresponse = (HttpWebResponse)myRequest.GetResponse();
      }
      catch (WebException ex)
      {
      if (ex.Response != null)
      {
      oresponse = (HttpWebResponse)ex.Response;
      }
      else
      {
      throw ex;
      }
      }  dataStream = oresponse.GetResponseStream();  try
      {
        
      StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("gb2312"));  string responseFromServer = reader.ReadToEnd();  reader.Close();
      dataStream.Close();
      oresponse.Close();  }
      catch (Exception k1)
      {
      throw k1;
      }
          }
    这个是阿里妈妈登录的,你对照看一下
      

  4.   

    登录这块,主要是如何获取COOKIE及将cookie发回去
      

  5.   

    已经看了  淘宝登陆如果不点安全控件 post密码是明文的
      

  6.   

    自己断点 调试 看走了 写入 cookie 没有啊
      

  7.   

    淘宝不是有openapi吗,干吗费这神...
      

  8.   

    不想用api  那个手续有点麻烦
      

  9.   

    taobao 登陆我做过不过在以前的公司。。年前走也没拿过来     
      

  10.   

    账号:sxjsnz 密码:ceshi123
      

  11.   

    [Quote=引用 9 楼 zhgroup 的回复:]登录这块,主要是如何获取COOKIE及将cookie发回去
    [/Quote
    ....我基本上把COOKIE当SESSION用。
      

  12.   

    求代码啊。我现在也想做这块 
    能发份登录实现代码到邮箱[email protected]吗?
      

  13.   

    我也要!!!!![email protected]
      

  14.   

    楼主帮忙解惑哈,我这出现
    parent.suc() 访问无权限。 该砸整喃?
      

  15.   

    这楼主怎么回事,问题解决了,就没声儿了?给发份源码中不?[email protected]
      

  16.   

    刚看到帖子,不好意思,源码在以前的公司,不好意思
    大概说一下当时解决的流程:
    第一次请求获取数据:(最关键token这个值,保存,或者将获取到的Cookie保存)
    第二次发送登陆请求携带Cookie一起发送,登陆成功PS:CookieContainer这个对象比较重要
      

  17.   


    请教一下楼主~ 有些值怎么找不到在哪,比如umto tid 
    CookieContainer 这个对象重要,怎么没有看到有地方给它赋值呢?请楼主指教啊