public void EnviarPedido() { string URL = $"https://localhost:44323/api/Pedidos"; string urlParameters = ""; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(URL); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue((string)Session["userToken"]); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); // List data response. JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); HttpResponseMessage response = client.PutAsync(urlParameters, new StringContent(serializer.Serialize(Session["Carrinho"]), Encoding.UTF8, "application/json")).Result; // Blocking call! Program will wait here until a response is received or a timeout occurs. //Dictionary<string, Object> resultado = (Dictionary<string, Object>)serializer.DeserializeObject(response.Content.ReadAsStringAsync().Result); if (response.IsSuccessStatusCode) { Session["Carrinho"] = new SblendersAPI.Models.Pedido(0, 0, 0, DateTime.Now, "", new PedidoProduto[0]); Response.Redirect("ConfirmacaoPedido.aspx"); } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "traçar rota", "tracarRotaReverso()", true); } }
protected void Session_Start(object sender, EventArgs e) { Session["userID"] = null; Session["userToken"] = null; Session["userRID"] = null; Session["Carrinho"] = new SblendersAPI.Models.Pedido(0, 0, 0, DateTime.Now, "", new PedidoProduto[0]); }