Esempio n. 1
0
        public async Task postEcho2(String url)
        {
            // string serv = "http://192.168.0.201:8080/ifire/echo.serv?t=echo&method=postEcho2";
            using (var client = new HttpClient()) {
                try {
                    Debug.WriteLine(" ---------    ---------    ------- ");
                    // StringContent content = HelloForm.getPostPayload();
                    EchoPayload   echoPay = new EchoPayload("I'm UnitTest1.");
                    StringContent content = new StringContent(echoPay.ToString(), Encoding.UTF8, "application/json");

                    /*
                     * var values = new Dictionary<string, string> {
                     *  { "thing1", "hello" },
                     *  { "thing2", "world" } };
                     *
                     * var content = new FormUrlEncodedContent(values);
                     */

                    var responseTsk = await client.PostAsync(url, content);

                    var responseString = await responseTsk.Content.ReadAsStringAsync();

                    Debug.WriteLine(responseString);
                } catch (HttpRequestException ex) {
                    Debug.WriteLine(" ----  ----  ----  ----  ----  ---- RRROREE ERROR ERROR ERROR ERROR ");
                    Debug.WriteLine(ex.Message);
                }
            }
        }
Esempio n. 2
0
        private async Task <JObject> PerformEchoRequest(JObject payload, Configuration config, ILambdaContext lambdaContext)
        {
            var client = new PubSubClient(config, lambdaContext);

            var         sw           = Stopwatch.StartNew();
            EchoPayload outgoingEcho = new EchoPayload()
            {
                Salt = Guid.NewGuid().ToString()
            };
            EchoPayload response = await client.RequestBridge <EchoPayload>(AloxiMessageOperation.Echo, outgoingEcho);

            sw.Stop();

            if (!(response?.Salt == outgoingEcho.Salt))
            {
                throw new Exception("Echo response invalid");
            }

            Log.Info(lambdaContext, $"Successful echo, took {sw.Elapsed.TotalSeconds}s");
            return(CreateResponse(new { Message = "Echo fine", DurationInSeconds = sw.Elapsed.TotalSeconds, Salt = response.Salt }));
        }