In pratica sto cercando di realizzare un programmino in C# che si collega con google Calendar, ed ho un problema a fare l'autenticazione. Il mio codice è il seguente:
WebRequest request = WebRequest.Create("https://www.google.com/accounts/ClientLogin");
request.Method = "POST";
String dataPost = "<form Email=miaemail Passwd=miapassword source=exampleCo-exampleApp-1 service=cl>";
byte[] byteArray = Encoding.UTF8.GetBytes(dataPost);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).Stat usDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
Ora il problema credo sia nella stringa dataPost, a mio parere sbaglio a scriverla. Nella guida mi dice la seguente:
The POST body should contain a set of query parameters, as described in the following table. They should look like parameters passed by an HTML form, using the application/x-www-form-urlencoded content type.
Parameter Description
Email The user's email address.
Passwd The user's password.
source Identifies your client application. Should take the form companyName-applicationName-versionID; below, we'll use the name exampleCo-exampleApp-1.
service The string cl, which is the service name for Google Calendar.
Grazie per qualsiasi aiuto