2012-07-01 50 views
-2

我試圖使用WebClient驗證Google帳戶。使用WebClient驗證Google帳戶

class PostDataBuilder 
{ 
    private static Dictionary<string, string> 
     ToPropertyDictionary(object data) 
    { 
     var values = data 
      .GetType() 
      .GetProperties() 
      .Select(x => new { 
           Key = x.Name, 
           Value = x.GetValue(data, null) 
          }); 

     var result = new Dictionary<string, string>(); 
     foreach (var item in values) 
      result.Add(item.Key, item.Value.ToString()); 

     return result; 
    } 

    public static string Build(object data) 
    { 
     string result = ""; 
     var dict = ToPropertyDictionary(data); 
     foreach (var name in dict.Keys) 
      result += name + "=" + HttpUtility.UrlEncode(dict[name]) + "&"; 
     return result.Substring(0, result.Length - 1); 
    } 
} 

class Program 
{ 
    static void Main(string[] args) 
    { 
     string postText = PostDataBuilder.Build(
     new 
     { 
      dsh = "-1903339439726094408", 
      GALX = "-Ggrv6gqusk", 
      timeStmp = "", 
      secTok = "", 
      Email = "[email protected]", 
      Passwd = "WrongPassword", 
      signIn = "?????", 
      rmShown = "1" 
     }); 

     byte[] data = Encoding.UTF8.GetBytes(postText); 

     WebClient wc = new WebClient(); 
     byte[] result = wc.UploadData(
      new Uri("https://accounts.google.com/ServiceLoginAuth"), 
      "POST", data); 

     string resultText = Encoding.UTF8.GetString(result); 
    } 
} 

ResultText變量已設置,即使數據是正確的。怎麼了?

回答

1

您不應該使用Google之類的登錄服務,或嘗試僞造瀏覽器。最後,它可能被認爲是企圖黑客攻擊或其他任何事情,並且很可能在下一次更新他們的頁面時(或者甚至僅僅因爲您的IP更改)而被打破。

改爲使用OpenID或OAuth,如here所述。

相關問題