Code:
using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); BillViewModel p = new BillViewModel { username = "Test_CBMS", password = "test@321", seller_pan = "999999999", buyer_pan = "123456789", buyer_name="", fiscal_year = "2073.074", invoice_number="102", invoice_date="2074.07.06", total_sales=1000.01, taxable_sales_vat=1000.01, vat=130, excisable_amount=0, excise=0, taxable_sales_hst=0, hst=0, amount_for_esf=0, esf=0, export_sales=0, tax_exempted_sales=0,isrealtime=true, datetimeclient = Datetime.now }; client.BaseAddress = new Uri("http://202.166.207.75:9050"); var response = client.PostAsJsonAsync("api/bill", p).Result; if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync(); Console.Write(result.Result); Console.ReadLine(); } else { Console.Write("Error"); Console.ReadLine(); } }
It tried it as following
Code:
Using client = New HttpClient() client.DefaultRequestHeaders.Accept.Clear() client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json")) Dim p As BillViewModel = New BillViewModel With { .username = "Test_CBMS", .password = "test@321", .seller_pan = "999999999", .buyer_pan = "123456789", .buyer_name = "", .fiscal_year = "2073.074", .invoice_number = "102", .invoice_date = "2074.07.06", .total_sales = 1000.01, .taxable_sales_vat = 1000.01, .vat = 130, .excisable_amount = 0, .excise = 0, .taxable_sales_hst = 0, .hst = 0, .amount_for_esf = 0, .esf = 0, .export_sales = 0, .tax_exempted_sales = 0, .isrealtime = True, .datetimeClient = DateTime.Now } client.BaseAddress = New Uri("http://202.166.207.75:9050") 'Dim response = client.PutAsync("api/bill", p).Result Dim response = client.PostAsJsonAsync("api/bill", p).Result If response.IsSuccessStatusCode Then Dim result = response.Content.ReadAsStringAsync() Console.Write(result.Result) Console.ReadLine() Else Console.Write("Error") Console.ReadLine() End If End Using
but is show error in " Dim response = client.PostAsJs onAsync("api/bill", p).Result"
it says
'PostAsJsonAsyn c' is not a member of 'System.Net.Htt p.HttpClient'.
Please please please help me.
Thank you.
Comment