示例#1
0
        /////// TEST A ONLY METHOD

        /*
         *
         * //////////////////////////////////////////// GET auth
         *
         *
         *
         * public static async Task<AuthResponseModel> authRequest(AuthRequestModel request)
         * {
         *  //Console.WriteLine("authReq::");
         *  //HttpClient cTest = getPhoenixClient();// fixing with change its position get out this method.
         *  HttpResponseMessage response = await cTest1.PostAsJsonAsync<AuthRequestModel>("auth", request);
         *  if (response.StatusCode == HttpStatusCode.OK)
         *  {
         *      //Console.WriteLine("StatusOk::");
         *      //string json = JsonConvert.SerializeObject(request);
         *      //StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
         *      //AuthResponseModel r = await response.Content.ReadAsAsync<AuthResponseModel>(new[] { new JsonMediaTypeFormatter() });
         *      AuthResponseModel r = await response.Content.ReadAsAsync<AuthResponseModel>();
         *      Console.WriteLine("auth::");
         *      return r;
         *  }
         *  else
         *  {
         *      //Console.WriteLine("Status 500::");
         *      return null;
         *  }
         * }
         *
         * //-------------
         * //////////////////////////////////////////// GET getData
         * public static async Task<GetDataResponseModel> getDataRequest(GetDataRequestModel request, string token)
         * {
         *  //HttpClient cTest = getPhoenixClient();// fixing with change its position get out this method.
         *  cTest1.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token);
         *  HttpResponseMessage response = await cTest1.PostAsJsonAsync("getData", request);
         *  if (response.StatusCode == HttpStatusCode.OK)
         *  {
         *      //GetDataResponseModel r = await response.Content.ReadAsAsync<GetDataResponseModel>(new[] { new JsonMediaTypeFormatter() });
         *      GetDataResponseModel r = await response.Content.ReadAsAsync<GetDataResponseModel>();
         *      Console.WriteLine("GetData::"+token);
         *      return r;
         *  }
         *  else
         *  {
         *      return null;
         *  }
         * }
         *
         * //-------------
         * //////////////////////////////////////////// GET sendData
         * public static async Task<SendDataResponseModel> sendDataRequest(SendDataRequestModel request)
         * {
         *  //HttpClient cTest = getPhoenixClient();// fixing with change its position get out this method.
         *  HttpResponseMessage response = await cTest1.PostAsJsonAsync("sendData", request);
         *  if (response.StatusCode == HttpStatusCode.OK)
         *  {
         *      //SendDataResponseModel r = await response.Content.ReadAsAsync<SendDataResponseModel>(new[] { new JsonMediaTypeFormatter() });
         *      SendDataResponseModel r = await response.Content.ReadAsAsync<SendDataResponseModel>();
         *      Console.WriteLine("SendData::");
         *      return r;
         *  }
         *  else
         *  {
         *      return null;
         *  }
         * }
         *
         * //-------------
         * //////////////////////////////////////////// GET generateSms
         * public static async Task<GenerateSmsResponseModel> generateSmsRequest(GenerateSmsRequestModel request)
         * {
         *  //HttpClient cTest = getPhoenixClient();// fixing with change its position get out this method.
         *  HttpResponseMessage response = await cTest1.PostAsJsonAsync("generateSms", request);
         *  if (response.StatusCode == HttpStatusCode.OK)
         *  {
         *      //GenerateSmsResponseModel r = await response.Content.ReadAsAsync<GenerateSmsResponseModel>(new[] { new JsonMediaTypeFormatter() });
         *      GenerateSmsResponseModel r = await response.Content.ReadAsAsync<GenerateSmsResponseModel>();
         *      Console.WriteLine("GenerateSms::");
         *      return r;
         *  }
         *  else
         *  {
         *      return null;
         *  }
         * }
         *
         * //-------------
         * //////////////////////////////////////////// GET validateSms
         * public static async Task<ValidateSmsResponseModel> validateSmsRequest(ValidateSmsRequestModel request)
         * {
         *  //HttpClient cTest = getPhoenixClient();// fixing with change its position get out this method.
         *  HttpResponseMessage response = await cTest1.PostAsJsonAsync("validateSms", request);
         *  if (response.StatusCode == HttpStatusCode.OK)
         *  {
         *      //ValidateSmsResponseModel r = await response.Content.ReadAsAsync<ValidateSmsResponseModel>(new[] { new JsonMediaTypeFormatter() });
         *      ValidateSmsResponseModel r = await response.Content.ReadAsAsync<ValidateSmsResponseModel>();
         *      Console.WriteLine("ValidateSms::");
         *      return r;
         *  }
         *  else
         *  {
         *      return null;
         *  }
         * }
         *
         * //-------------
         * //////////////////////////////////////////// GET closeOperation
         * public static async Task<CloseOperationResponseModel> closeOperationRequest(CloseOperationRequestModel request)
         * {
         *  //HttpClient cTest = getPhoenixClient();// fixing with change its position get out this method.
         *  HttpResponseMessage response = await cTest1.PostAsJsonAsync("closeOperation", request);
         *  if (response.StatusCode == HttpStatusCode.OK)
         *  {
         *      //CloseOperationResponseModel r = await response.Content.ReadAsAsync<CloseOperationResponseModel>(new[] { new JsonMediaTypeFormatter() });
         *      CloseOperationResponseModel r = await response.Content.ReadAsAsync<CloseOperationResponseModel>();
         *      Console.WriteLine("CloseOperation::");
         *      return r;
         *  }
         *  else
         *  {
         *      return null;
         *  }
         *
         * }
         *
         *
         * ////////////static HttpClient cTest1 = getPhoenixClient();
         * //static HttpClient cTest2 = getPhoenixClient(test1.Tken);
         * //static HttpClient cTest2;
         */
        //HttpClient cTest1 = getPhoenixClient();

        ////////////PRINTS
        static void ShowAuth(AuthResponseModel authT)
        {
            Console.WriteLine($"Auth credentials.\nkey: {authT.AuthKey}\nresponseCode: {authT.ResponseCode}\nresponseMessage: {authT.ResponseMessage}\n\n");
            //test1.Tken = authT.AuthKey;
            //cTest2 = getPhoenixClient(authT.AuthKey);
        }
示例#2
0
        private static async Task <GetDataResponseModel> GetDataResponseAsync(string requestname, GetDataRequestModel requestname2, AuthResponseModel token)
        {
            //var clint = HttpClientFactory;
            var request   = new HttpRequestMessage(HttpMethod.Post, requestname);
            var serialize = JsonSerializer.Serialize(requestname2);

            //request.RequestUri = new Uri(Constants.URL_BASE_PARAM);
            //httpClientFactory cln = new Uri()

            request.Content = new StringContent(serialize, System.Text.Encoding.UTF8, "application/json");
            //request.Headers = new HttpRequestHeaders()
            //var clientIH = httpClientFactory.CreateClient("VerifyService"); //getClient
            //var clientIH = httpClientFactory.CreateClient("VerifyService");
            //client.BaseAddress = new Uri(Constants.URL_BASE_PARAM);
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AuthKey);
            //clientIH.BaseAddress = new Uri(Constants.URL_BASE_PARAM);

            //var response = await clientIH.SendAsync(request);
            var response = await client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                using var responseStream = await response.Content.ReadAsStreamAsync();//////////  INSPECTION POINT TO VISUALIZE THE VALUES OF INPUTS!!!!!!!

                var responseModel = await JsonSerializer.DeserializeAsync <GetDataResponseModel>(responseStream);

                return(responseModel);
            }
            else
            {
                // using var responseStream2 = await response.Content.ReadAsStreamAsync();
                // var responseModel = await JsonSerializer.DeserializeAsync<AuthResponseModel>(responseStream2);
                // return responseModel;
                return(new GetDataResponseModel()
                {
                    ResponseCode = (int)response.StatusCode
                });
                //return <AuthResponseModel> ;
            }
        }