Exemple #1
0
        //POST json data to value
        private static string PostEncodedValueToAPI(string guid, string encodedValue, string algorithmName)
        {
            PostEncodedValueRequest postValues = new PostEncodedValueRequest();

            postValues.emailAddress = "*****@*****.**";
            postValues.encodedValue = encodedValue;
            postValues.name         = "Moises David Martinez Padilla";
            postValues.repoUrl      = "https://github.com/moisesmartinez/AADevChallenge";
            postValues.webhookUrl   = "http://aawebhookhandler.apphb.com/WebhookHandler";

            //Create json string
            string jsonContent = JsonConvert.SerializeObject(postValues);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format(postEncodedValueURL, guid, algorithmName));

            request.Method      = "POST";
            request.ContentType = "application/json";
            request.Accept      = "application/json";

            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            Byte[] byteArray = encoding.GetBytes(jsonContent);

            request.ContentLength = byteArray.Length;

            using (Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
            }
            long length = 0;

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    length = response.ContentLength;

                    using (Stream responseStream = response.GetResponseStream())
                    {
                        StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                        return(reader.ReadToEnd());
                    }
                }
            }
            catch (WebException ex)
            {
                // Log exception and throw as for GET example above
                throw;
            }
        }
        //POST json data to value
        private static string PostEncodedValueToAPI(string guid, string encodedValue, string algorithmName)
        {
            PostEncodedValueRequest postValues = new PostEncodedValueRequest();
            postValues.emailAddress = "*****@*****.**";
            postValues.encodedValue = encodedValue;
            postValues.name = "Moises David Martinez Padilla";
            postValues.repoUrl = "https://github.com/moisesmartinez/AADevChallenge";
            postValues.webhookUrl = "http://aawebhookhandler.apphb.com/WebhookHandler";

            //Create json string
            string jsonContent = JsonConvert.SerializeObject(postValues);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format(postEncodedValueURL, guid, algorithmName));
            request.Method = "POST";
            request.ContentType = "application/json";
            request.Accept = "application/json";

            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            Byte[] byteArray = encoding.GetBytes(jsonContent);

            request.ContentLength = byteArray.Length;

            using (Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
            }
            long length = 0;
            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    length = response.ContentLength;

                    using (Stream responseStream = response.GetResponseStream())
                    {
                        StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                        return reader.ReadToEnd();
                    }
                }
            }
            catch (WebException ex)
            {
                // Log exception and throw as for GET example above
                throw;
            }
        }