Exemplo n.º 1
0
        public Token GerarTokenPOST(ConfToken token)
        {
            try
            {
                ServicePointManager.ServerCertificateValidationCallback += (a, b, c, d) => true;
                token.Grant_type = "client_credentials";

                string urlForm1 = this.Url;

                string urlRequestBody = string.Format("client_id={0}&client_secret={1}&grant_type={2}", this.ClienteId, this.SecretyKey, token.Grant_type);

                byte[] byteLenghtRequestBody = Encoding.UTF8.GetBytes(urlRequestBody);
                WebRequest request = WebRequest.Create(urlForm1);

                request.ContentLength = urlRequestBody.Length;
                request.ContentType = "application/x-www-form-urlencoded";
                request.Method = "POST";
                var dataServer = request.GetRequestStream();
                dataServer.Write(byteLenghtRequestBody, 0, byteLenghtRequestBody.Length);
                WebResponse response = request.GetResponse();
                dataServer.Close();
                Stream dataBaseServer = response.GetResponseStream();
                string json = readStream(dataBaseServer);
                Token tokenCreate = readJsonToken(json);
                return tokenCreate;
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                ConfToken ct = new ConfToken();
                ct.GerarPerimetrosGET(tokenGerado);

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // Carregamento barra status
                progressBar1.Value = 50;
                progressBar1.Update();
                ConfToken token = new ConfToken(url.Text, clienteid.Text, secretykey.Text);
                this.tokenGerado = token.GerarTokenPOST(token);
                // Carregamento barra status
                progressBar1.Value = 100;
                progressBar1.Update();

                MessageBox.Show("Token Gerado Com Sucesso!");

                progressBar1.Value = 0;
                progressBar1.Update();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }