Using the latest VS2017 Enterprise, I'm trying to connect to an old REST Api with a Xamarin Cross Platform App, on the IOS side.
I've tried Microsoft.Net.Http nuget package in the PCL and System.Net.Http in the IOS-specific app.
I'm trying to login, and then connect to the old(2012) REST Api. Because it's VS2017 Enterprise, I have the iPad Air emulator running locally with just a network connection to a MacBook Pro.
Here is the code in PCL, using Microsoft.Net.Http
Login.xaml
<Button x:Name="btn_Login" Text="Login" Clicked="btn_Login_Clicked" />
Login.xaml.cs
private void btn_Login_Clicked(object sender, EventArgs e)
{
person.Login(username.Text, password.Text);
}
Person.cs
public async void Login(string u, string p)
{
string validate = "the correct url"; //it's correct but private, can't share
var req = new HttpRequestMessage();
req.RequestUri = new Uri(validate);
req.Method = HttpMethod.Get;
req.Headers.Add("Accept", "application/json");
req.Headers.Add("clientAuth", "test123");
req.Headers.Add("clientUN", u.Trim());
req.Headers.Add("clientPWD",p.Trim());
using (var client = new HttpClient()) {
HttpResponseMessage resp = await client.SendAsync(req).ConfigureAwait(false);
}
}
The client.SendAsync()
function immediately causes the code to jump to the end of
private void btn_Login_Clicked(object sender, EventArgs e)
in Login.xaml.cs
I've spent almost 30 hours, trying all sorts of different things and I'm completely lost and exhausted. I've also tried this using System.Net.Http in the IOS app using an Interface from the Portable code to the IOS code, same behavior.
The above code works perfectly fine in a Windows Application, nothing to do with Xamarin.