我从stackoverflow的某个地方得到了这段代码。我无法理解。它用于登录 youtube。我是 C# 和 OOPS 的新手。所以任何人都可以向我解释一些事情:
1) 在第 3 行
HttpWebRequest request = GetNewRequest("https://accounts.google.com/ServiceLoginAuth", cookies);
HttpWebRequest 是一个类,request 是一个对象。但是为什么在那之后不使用 New 关键字呢?这是什么“GetNewRequest”?它是一种方法吗?大多数时候,我们使用带有 New 关键字的类的构造函数。那么我可以得出结论,我可以在那里使用该类的任何方法吗?有没有必要使用new关键字和构造函数?
2) 在第 6 行
Dictionary<string, string> parameters = new Dictionary<string, string>
字典是类,参数是对象。但这是什么<string, string>
?我从来没有见过参数可以传递给一个类。
3) 在第 7 行
{
{"continue","https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26feature%3Dsign_in_button%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252F"},
{"service","youtube"},{"uilel","3"},{"dsh","157212168103955870"},{"hl","en_US"},
{"GALX","PTqcwpZb2aE"},{"pstMsg","1"},{"dnConn",""}, {"checkConnection","youtube%3A248%3A1"},
{"checkedDomains","youtube"}, {"timeStmp",""}, {"secTok",""}, {"Email","username"}, {"Passwd","password"},
{"signIn","Sign+in"}, {"PersistentCookie","yes"}, {"rmShown","1"}};
我看不懂这是什么?它不适合我在 C# 中阅读的任何语法。这是我以前从未见过的。
完整代码
public void Login()
{
HttpWebRequest request = GetNewRequest("https://accounts.google.com/ServiceLoginAuth", cookies);
request.Referer = "https://accounts.google.com/ServiceLogin?passive=true&continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26feature%3Dsign_in_button%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252F&uilel=3&hl=en_US&service=youtube";
request.Host = "accounts.google.com";
Dictionary<string, string> parameters = new Dictionary<string, string>{
{"continue","https%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26feature%3Dsign_in_button%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252F"},
{"service","youtube"},{"uilel","3"},{"dsh","157212168103955870"},{"hl","en_US"},
{"GALX","PTqcwpZb2aE"},{"pstMsg","1"},{"dnConn",""}, {"checkConnection","youtube%3A248%3A1"},
{"checkedDomains","youtube"}, {"timeStmp",""}, {"secTok",""}, {"Email","username"}, {"Passwd","password"},
{"signIn","Sign+in"}, {"PersistentCookie","yes"}, {"rmShown","1"}};
HttpWebResponse response = MakeRequest(request, cookies, parameters);
response.Close();
}