I got this piece of code from somewhere in stackoverflow. I am unable to understand it. It is used to login to youtube. Iam new to C# and OOPS. So can anyone explain me few thigs:
1) In the 3rd line
HttpWebRequest request = GetNewRequest("https://accounts.google.com/ServiceLoginAuth", cookies);
HttpWebRequest is a class and request is a object. But why New keyword is not used after that? and What is this “GetNewRequest” ? Is it a method? most of the time we use constructor of the class there with New keyword. So can I conclude that I can use any method of the class there? There is no need to use the new keyword and the constructor?
2) In the 6th line
Dictionary<string, string> parameters = new Dictionary<string, string>
Dictionary is class and parameters is the object. But what is this <string, string> there? I never seen parameters can be passed to a class.
3) In the 7th line
{
{"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"}};
I can’t understand what is this? It cant fit to any syntax I read in C#. It is something I have never seen before.
COMPLETE CODE
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();
}
GetNewRequestwould be a method that actually creates and returns the instance ofHttpWebRequest. So,newis not needed before the call toGetNewRequest.newis only needed when you are calling the constructor of the type in that same line as the declaration.<string, string>declaration afterDictionaryspecifies the key and value types, sinceDictionary<TKey, TValue>is a generic type._