Answer the question
In order to leave comments, you need to log in
How to call the API controller through the client?
There is a project with regular controllers, there is a project with api controllers. How to call from a regular api controller through an http client (a class library that is responsible for generating requests to the ip controller), there are links to the project, but the api controller method does not work
Answer the question
In order to leave comments, you need to log in
Class library, client for making queries
public CountryDTO find(int id)
{
try
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(Base_URL);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("country/" + id.ToString()).Result;
if (response.IsSuccessStatusCode)
return response.Content.ReadAsAsync<CountryDTO>().Result;
return null;
}
catch
{
return null;
}
}
CountryClient CC = new CountryClient();
public ActionResult Details(int id)
{
CountryDTO a = CC.find(id);
return View(a);
}
[ResponseType(typeof(CountryDTO))]
public IHttpActionResult GetCountry(int id)
{
countryRepository.GetCoById(id);
return Ok(countryRepository.GetCoById(id));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question