Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

PostAsync hanging

$
0
0

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.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>