Hi,
I'm trying to post some data to my web api but whenever I call the PostAsync, it just hangs and does not return results. When called from Fiddler or Postman, it returns data as expected so I can only assume that it has something to do with async/await.
Here my PostAsync code:
using (var client = new HttpClient())
{
var jsonData = JsonConvert.SerializeObject(data);
using (var response = await client.PostAsync(
uri,
new StringContent(jsonData,
Encoding.UTF8,
"application/json" )))
{
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<TResponse>(content);
}
}
}
It never hits the Response.IsSuccessStatusCode
And this is my ViewModel code:
private async Task SignInCommandAction()
{
try
{
var loginRequestDto = new LoginRequestDto
{
Email = this.Email,
Password = this.Password
};
var user = await this._dataService
.PostDataAsync<LoginRequestDto, LoginResponseDto>(@"Accounts/Login", loginRequestDto);
………
and finally, my PRISM DelegateCommand is defined as follows:
public DelegateCommand SignInCommand => _signInCommand ??
(this._signInCommand = new DelegateCommand(async () =>
{
await SignInCommandAction();
}));
Note that I thought the above definition was going to sort me out as I originally had it defined as:
public DelegateCommand SignInCommand => _signInCommand ??
(this._signInCommand = new DelegateCommand(SignInCommandAction));
which I thought might have been blocked by the UI thread or something similar.
Can anyone help?
Thanks.
T.