public async Task <nautaResponse> Simular(customer_info customer) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://smsteleyuma.azurewebsites.net/Service1.svc/TransferTo/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var nauta = new nautaInfo { account_number = this.account_number, product_id = this.product_id, monto = this.monto, simulation = "1", recipient_sms_notification = "1", sender_sms_notification = true, sender = new nautaUser { last_name = customer.lastname, middle_name = "", first_name = customer.firstname, email = customer.email, mobile = Convert.ToInt64(customer.phone1) }, recipient = new nautaUser { last_name = "", middle_name = "", first_name = "", email = this.account_number, mobile = 99999999 } }; try { var response = await client.PostAsync("nauta", nauta.AsJsonStringContent()); var Result = await response.Content.ReadAsStringAsync(); var nautaResponse = JsonConvert.DeserializeObject <nautaResponse>(Result); return(nautaResponse); } catch (Exception) { var nautaResponse = new nautaResponse(); nautaResponse.erroe_code = "-1"; nautaResponse.error_message = "Error de conección"; return(nautaResponse); } } }
public async Task <nautaResponse> nauta() { var json = JsonConvert.SerializeObject(this); using (var client = new HttpClient()) { var request = GetHttpRequestMessage("https://api.transferto.com/v1.1/transactions/fixed_value_recharges", HttpMethod.Post, new StringContent(json)); try { HttpResponseMessage response = await client.SendAsync(request); string result = await response.Content.ReadAsStringAsync(); var errores = JsonConvert.DeserializeObject <Errores>(result); if (errores.errors != null) { var nautaResponse = JsonConvert.DeserializeObject <nautaResponse>(result); nautaResponse.erroe_code = errores.errors[0].code.ToString(); nautaResponse.error_message = errores.errors[0].message.ToString(); return(nautaResponse); } else { var nautaResponse = JsonConvert.DeserializeObject <nautaResponse>(result); nautaResponse.erroe_code = "0"; nautaResponse.error_message = ""; return(nautaResponse); } } catch (Exception ex) { var nautaResponse = new nautaResponse(); nautaResponse.erroe_code = "-1"; nautaResponse.error_message = "Error de conexción"; return(nautaResponse); } } }