So I'm using Microsoft.Http.Net, with ModernHttpClient, and I'm getting an unhandled exception everytime I trigger a PostAsync() method....
In this case, the BaseUrl is a local API I'm developing with Laravel, but it also doesn't work with jsonplaceholder...
`
using ModernHttpClient;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace CSA
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Login : ContentPage
{
HttpClient Client = new HttpClient(new NativeMessageHandler());
public class AuthData {
public string username { get; set; }
public string password { get; set; }
}
public Login()
{
InitializeComponent();
logo_csa.Source = ImageSource.FromResource("CSA.Images.photo.jpg");
NavigationPage.SetHasNavigationBar(this, false);
Client.DefaultRequestHeaders.Add("Accept", "application/json");
}
private async void Button_Clicked(object sender, EventArgs e)
{
user.IsEnabled = false;
pass.IsEnabled = false;
LoginBtn.IsEnabled = false;
Indicator.IsVisible = true;
AuthFail.IsVisible = false;
var AuthAttempt = new AuthData();
AuthAttempt.username = user.Text;
AuthAttempt.password = pass.Text;
var content = JsonConvert.SerializeObject(AuthAttempt);
var Url = Application.Current.Properties["baseUrl"] + "/login";
var response = await Client.PostAsync(Url, new StringContent(content)); //This is the line where I get the crash
//var data = JsonConvert.DeserializeObject(content);
//await DisplayAlert("llala", data.ToString() , "OK");
}
}
}
`