Sujeet Raman

Sujeet Raman

  • 859
  • 927
  • 351.9k

Unhandled Exception In HttpClient web api call in asp.net core

Feb 4 2021 1:32 PM
In postman I issue a request with the following body against `http://localhost:2000/api/ProductQuality/Check`:
```json
{
"productid": "2274",
"productcorenumber": "1321",
"value": "AE1C1F-0363-D6F-B3D-AE0029A8",
"contacts": [
15998,
1012
],
"ispassed": "0",
"isok": "0",
"isgood": "false"
}
```
and this will come to here(I have one method in my controller)
```cs
[HttpPost("api/ProductQuality/Check")]
public async Task Check([FromBody] CheckInput input)
{
var result = await _Checker.Checkercall(input);
}
```
in `Checkercall` implementation I am calling another API(as of now calling the same for testing purposes)
```cs
public async Task Checkercall(CheckInput input)
{
QualityCheckResults QualityCheckInputResult = new QualityCheckResults();
using (var httpClient = new HttpClient())
{
var content = new StringContent(JsonConvert.SerializeObject(input), Encoding.UTF8, "application/json");
using (var response = await httpClient.PostAsync("https://localhost:2001/api/ProductQuality/Check", content))
//hope i have to give https here
{
string apiResponse = await response.Content.ReadAsStringAsync();
QualityCheckInputResult = JsonConvert.DeserializeObject(apiResponse);
}
}
return QualityCheckInputResult;
}
```
I am getting Unhandled Exception here but I couldn't understand the issue.

Answers (8)