First of all, this question is not a duplicate. I found this question and this answer. But it didn't solve my problem. I tried to accept permission. It seems accepted on api. But app stucks in loading. Because I have a problem to get a response from web api. I put breakpoints. But it does not hit any line after SendAsync or PutAsync and no exception/error. It tested on postman and returned 200. This api is using for web project also and it works fine.
This code was working before:
public async Task AcceptPermission(string Id)
{
try
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);
var request = new HttpRequestMessage(HttpMethod.Put, BaseAddress + "leave/response/" + Id + "/Accepted");
var response = await client.SendAsync(request);
var jsonResp = response.Content.ReadAsStringAsync().Result;
}
catch (Exception ex)
{
...
}
}
I tried these from taking a reference to the other questions:
- Changed base address http to https
- Removed .Result from response
- Added ConfigureAwait(false)
I changed my code with this and also didn't work:
public async Task<string> AcceptPermission(string Id)
{
try
{
string uri = BaseAddress + "leave/response/" + Id + "/Accepted";
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);
HttpContent content = new StringContent(JsonConvert.SerializeObject(Id), Encoding.UTF8, "application/json");
var response = await client.PutAsync(uri, content).ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
...
}
else
{
...
}
}
catch (Exception ex)
{
...
}
}
I don't understand what did I wrong? Any help is very useful. Thanks for your help.