I am able to call the Web api method in client side and now i want make it in c# code. Here i am writing my jquery code.
$(document).ready(function ()
{
$('#btnSubmit').click(function ()
{
var Params =
{
AsOndate: Todate,
BCRefCode: 100,
AccID: 90000
};
$.ajax({
type: "GET",
url: 'http://localhost:51093/api/account/',
//url: 'http://192.168.0.171:51093/api/account/',
data: Params,
dataType: "json",
traditional: true,
success: ajaxSuccess,
error: ajaxError
});
});
and i am calling the web api method
public IEnumerable GetAccountListForMapping(Params param)
{
AccList _AccList = new AccList();
ListParams lstParam = new ListParams();
//lstParam.Add("@FromDate", Fromdate);
lstParam.Add("@AsOnDate", param.AsOndate);
lstParam.Add("@BCRefCode", param.BCRefCode);
lstParam.Add("@AccID", param.AccID);
_AccList = (AccrList)_AccList.GetAccountMappedList(lstParam);
return _AccList;
}
This is working good in jquery call.. And how to write the same C# code
This is what i tried
Params param1 = new Params();
param1.AsOndate = System.DateTime.Today;
param1.AccID = 90000;
param1.BCRefCode = 100;
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:51093/");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("/api/account", param1, new JsonMediaTypeFormatter()).Result;
if (response.IsSuccessStatusCode)
{.....
}