2012-02-29 73 views
2

我想用c#登錄youtube。我正在使用HttpWebRequest。 過程我下面:使用GET和解析GALX值使用c#登錄Youtube#

  1. 負載的登錄頁面
  2. POST用戶名/密碼連同GALX
  3. 得到一個元刷新頁面,使用GET
  4. 解析URL和負載
  5. 在每一步Cookie都是使用CookieContainer處理
  6. UserAgent,ContentType等標頭值已設置,並且AllowAutoRedirect爲true。

現在我收到以下Javascript代碼作爲響應。

var Ga, G = G || {}; 
    G.a = { g: "cookie_missing", f: "cookie_found", h: "gaia_failure" }; 
    var Gb = /\s*;\s*/; 
    var Gc = function() { 

     try 
     { 
      return new XMLHttpRequest 
     } 
     catch (a) 
     { 
      for (var b = ["MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"], c = 0; c < b.length; c++) 
       try 
       { 
        return new ActiveXObject(b[c]) 
       } 
       catch (d) { } 
     } 

     return null 
    }, 

    Gd = function() { 

     this.d = Gc(); this.b = {} 
    }; 
    Gd.prototype.oncomplete = function() { }; 

    Gd.prototype.send = function (a) { 

     var b = [], c; 
     for (c in this.b) { 
      var d = this.b[c]; 
      b.push(c + "=" + encodeURIComponent(d)) 
     } 
     var b = b.join("&"), e = this.d, f = this.oncomplete; 
     e.open("POST", a, !0); 
     e.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
     e.setRequestHeader("Content-length", "" + b.length); 
     e.onreadystatechange = function() { 
      4 == e.readyState && f({ status: e.status, text: e.responseText }) 
     }; 
     e.send(b) 
    }; 
    Gd.prototype.get = function (a) { 
     var b = this.oncomplete, c = this.d; c.open("GET", a, !0); 
     c.onreadystatechange = function() { 4 == c.readyState && b({ status: c.status, text: c.responseText }) }; 
     c.send() 
    }; 
    var Gf = function (a) { 
     this.c = a; this.i = this.j(); 
     if (null == this.c) throw new Ge("Empty module name"); 
    }; 
    Ga = Gf.prototype; 
    Ga.j = function() { 
     var a = window.location.pathname; 
     return a && 0 == a.indexOf("/accounts") ? "/accounts/JsRemoteLog" : "/JsRemoteLog" 
    }; 
    Ga.k = function (a, b, c) { 
     for (var d = this.i, e = this.c || "", d = d + "?module=" + encodeURIComponent(e), a = a || "", d = d + "&type=" + encodeURIComponent(a), b = b || "", d = d + "&msg=" + encodeURIComponent(b), c = c || [], a = 0; a < c.length; a++) d = d + "&arg=" + encodeURIComponent(c[a]); 
     try { 
      var f = Math.floor(1E4 * Math.random()), d = d + "&r=" + ("" + f) 
     } 
     catch (g) { } 
     return d 
    }; 
    Ga.send = function (a, b, c) { 
     var d = new Gd; d.b = {}; 
     try { 
      var e = this.k(a, b, c); 
      d.get(e) 
     } catch (f) { } 
    }; 
    Ga.error = function (a, b) { 
     this.send("ERROR", a, b) 
    }; 
    Ga.warn = function (a, b) { 
     this.send("WARN", a, b) 
    }; 
    Ga.info = function (a, b) { 
     this.send("INFO", a, b) 
    }; 
    Ga.m = function (a) { 
     var b = this; 
     return function() { 
      try { 
       return a.apply(null, arguments) 
      } 
      catch (c) { 
       throw b.error("Uncatched exception: " + c), c; 
      } 
     } 
    }; 

    var Ge = function() { }; 
    G = G || {}; 
    G.e = G.e || new Gf("report_sid_status"); 
    G.l = function (a, b, c) { 
     if (window.postMessage && window.parent) { 
      if (a) { 
       a: 
       { 
        if (document.cookie) 
         for (var a = b + "=", b = document.cookie.split(Gb), d = 0; d < b.length; d++) { 
          var e = b[d], e = e.replace(/^\s+/, ""), e = e.replace(/\s+$/, ""); 
          if (0 == e.indexOf(a)) { 
           a = e.substr(a.length); 
           break a 
          } 
         } 
        a = null 
       } 
       a = null == a ? G.a.g : G.a.f 
      } 
      else a = G.a.h; window.parent.postMessage(a, c) 
     } 
    }; 

    G_checkSidAndReport = G.e.m(G.l); 

    G_checkSidAndReport('0', 'SID', 'https:\x2F\x2Faccounts.google.com'); 

現在該做什麼?使用這個程序,我可以成功登錄Gmail,但不是youtube。我認爲javascript發佈到服務器,但我無法找出實際發佈的內容。

+0

這類問題一直是[問](http://stackoverflow.com/questions/9336395/login-using-webclient-or-httpwebrequest)[多](HTTP:/ /stackoverflow.com/questions/6069302/how-would-i-programatically-login-to-a-site-such-as-codeproject-or-stackoverflow)[times](http://stackoverflow.com/questions/3507855/c-sharp-login-examples)[before](http://stackoverflow.com/questions/1336310/login-to-web-page-using-c-sharp)。 – 2012-02-29 05:11:26

+0

請再次閱讀該問題! – 2012-02-29 06:41:14

回答

1

我在我的代碼從PHP相同的位置,如果你設法弄清楚請讓我知道。我認爲關鍵在於這些參數的以下功能。

G.l=function(a='1',b='SID',c='https:\x2F\x2Faccounts.google.com'){ 
if(window.postMessage&&window.parent){ 
    if(a){ 
     a:{ 
      if(document.cookie)for(var a=b+"=",b=document.cookie.split(Gb),d=0; 
      d&lt; 
      b.length; 
      d++){ 
       var e=b[d],e=e.replace(/^\s+/,""),e=e.replace(/\s+$/,""); 
       if(0==e.indexOf(a)){ 
        a=e.substr(a.length); 
        break a 
       } 

      } 
      a=null 
     } 
     a=null==a?G.a.g:G.a.f 
    } 
    else a=G.a.h; 
    window.parent.postMessage(a,c) 
} 

}

+0

聯繫我[email protected] – Evan 2012-03-27 06:30:31

+0

NOP,這只是一個修剪功能的SID餅乾。 – Evan 2012-03-27 07:04:53