public static void showAlertCommon(string message, Page page) { //ScriptManager.RegisterStartupScript(page, page.GetType(), "", "alert('" + message + "');", true); }
public async Task <Tuple <T, string> > PostDataAsync <T>(string payload, string url, Page page, string TripType) { try { //string uri = $"{Urls.BaseURL}{url}"; using (HttpClient client = new HttpClient()) { //fetch csrf var CSRF_TOKEN = string.Empty; client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers .AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", ODataService.username, ODataService.password)))); client.DefaultRequestHeaders.Add("X-CSRF-TOKEN", "FETCH"); //client.DefaultRequestHeaders.Add("x-smp-appcid", "'" + page.Session["APPCID"] + "'"); HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false); CSRF_TOKEN = response.Headers.GetValues("x-csrf-token").FirstOrDefault(); if (CSRF_TOKEN == null || CSRF_TOKEN.Equals(string.Empty)) { return(new Tuple <T, string>(default(T), "CSRF error")); } client.DefaultRequestHeaders.Remove("X-CSRF-TOKEN"); client.DefaultRequestHeaders.Add("X-CSRF-TOKEN", CSRF_TOKEN); client.DefaultRequestHeaders.Add("Accept", "application/xml"); //client.DefaultRequestHeaders.Add("x-smp-appcid","'"+page.Session["APPCID"]+"'"); HttpContent content = new StringContent(payload); content.Headers.Remove("Content-Type"); if (url.Contains("batch")) { content.Headers.Add("Content-Type", "multipart/mixed;boundary=batch"); } else { content.Headers.Add("Content-Type", "application/xml"); } HttpResponseMessage orderResponse = await client.PostAsync(url + "et_lead_prospect_newSet", content).ConfigureAwait(false); var result = await orderResponse.Content.ReadAsStringAsync().ConfigureAwait(false); string message = result; if (!orderResponse.IsSuccessStatusCode) { //HTTP/1.1 400 Bad Request if (result.ToLower().Contains("HTTP/1.1 400 Bad Request")) { message = "Bad request.Please try again later." + "\n" + result; var errorOutput = result; //var errorMsg = JObject.Parse (errorOutput).SelectToken ("error.message.value").ToString (); return(new Tuple <T, string>(default(T), "")); } else { message = result; } // showAlert(message, page, TripType); return(new Tuple <T, string>(default(T), orderResponse.StatusCode.ToString())); } else { // page.On // message = "Plan created succesfully."; // showAlert(message, page, TripType); string message1 = "Thank you for Submission !"; // ScriptManager.RegisterStartupScript(page, page.GetType(), "", "alert('" + message1 + "');window.location='LeadForm.aspx';", true); } //showAlert(message, page); return(new Tuple <T, string>(default(T), result)); // return null; } } catch (Exception ex) { //Debug.WriteLine (ex.Message); return(new Tuple <T, string>(default(T), ex.Message)); } }
public async Task <string> GetPostData(string payload, string service_type, string url, Page page, string TripType) { this.page = page; String result = ""; if (service_type == ODataService.Service_get) { result = GetODataService(url); return(result); } else if (service_type.Equals(ODataService.Service_post)) { await PostDataAsync <string>(payload, url, page, TripType); } else if (service_type.Equals(ODataService.Service_put)) { } return(result); }