private void DataExtract(MPOP_Dashboard.MyTelBillCharge mytelbillcharge) { try { mytelbillcharge.MyTelBillChargeID = null; mytelbillcharge.MSISDN = txtMSISDNNo.Text.Trim(); mytelbillcharge.Amount = int.Parse(txtAmount.Text); mytelbillcharge.Result = txtResult.Text.Trim(); mytelbillcharge.CreatedDate = null; mytelbillcharge.CreatedBy = Session["username"].ToString(); } catch (Exception ex) { } }
public async Task PostFormUrlEncodedAsync(string url, IEnumerable <KeyValuePair <string, string> > postData) { try { using (var httpClient = new HttpClient(new HttpClientHandler { UseProxy = true })) { using (var content = new FormUrlEncodedContent(postData)) { content.Headers.Clear(); content.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "apismpop:u6Q6qwe%EAu%nV8u"); var plainTextBytes = Encoding.ASCII.GetBytes("apismpop:u6Q6qwe%EAu%nV8u"); string val = System.Convert.ToBase64String(plainTextBytes); httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + val); var method = new HttpMethod("POST"); var json = JsonConvert.SerializeObject(postData, Formatting.Indented); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); var rp = httpClient.PostAsync(url, stringContent).Result; txtResult.Text = await rp.Content.ReadAsStringAsync(); lblMessage.Text = ConfigurationManager.AppSettings["Successful"]; MPOP_Dashboard.MyTelBillCharge mytelbillcharge = new MPOP_Dashboard.MyTelBillCharge(); DataExtract(mytelbillcharge); db.sp_MPOP_Dashboard_MyTelBillCharge_CRUD(mytelbillcharge.MyTelBillChargeID, mytelbillcharge.MSISDN, mytelbillcharge.Amount, mytelbillcharge.Result, mytelbillcharge.CreatedDate, mytelbillcharge.CreatedBy); } } } catch { lblMessage.Text = ConfigurationManager.AppSettings["Unsuccessful"]; } }