Sujeet Raman

Sujeet Raman

  • 864
  • 927
  • 354.2k

How to send post parameter in httpclient in asp.net core 3.1?

Feb 3 2021 8:15 AM
Hi
 
I am trying an http call to get the input response..my strategy is i am calling httpcall from controller with a general url..i am facing some issues i am getting internal server error also i dont know my way is right please suggest me if i am wrong..
 
1.input parameter passing is right here?
2.I am getting server error because of this i dont know why? please help
 
my controller class and the url i am calling from postman is api/Details/Check this link i will put in postman and doing all
  1. [HttpPost("api/Details/Check")]  
  2. public async Task Check([FromBody] details input)  
  3. {  
  4. var result = await _resultcheker .ResultCheckercall(input);  
  5. }  
  6. the call will goto ResultCheckercall  
  7. public async Task Checkercall(CheckInput input)  
  8. {  
  9. CheckResults CheckInputResult = new yCheckResults();  
  10. using (var httpClient = new HttpClient())  
  11. {  
  12. var content = new StringContent(JsonConvert.SerializeObject(input), Encoding.UTF8, "application/json");  
  13. using (var response = await httpClient.PostAsync("https://localhost:5443/api/Alldetails/details", content))  
  14. {  
  15. string apiResponse = await response.Content.ReadAsStringAsync();  
  16. CheckInputResult = JsonConvert.DeserializeObject(apiResponse);  
  17. }  
  18. }  
  19. return yCheckInputResult;  
  20. }  

Answers (10)