Visualizzazione dei risultati da 1 a 2 su 2

Discussione: [C#] Webrequest

  1. #1

    [C#] Webrequest

    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

  2. #2
    sono riuscito a risolvere il problema e riesco a fare il login.

    Ora però ho il problema che per le successive richieste che vado a fare dovrei utilizzare il parametro stringa auth che mi ritorna il sito quando faccio il login.

    Come faccio a mettere come header nelle mie richieste questo parametro?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.