1
votes

I am new to Xamarin and currently implementing a Xamarin.Forms application which has a XAML based Login page with Username/Password fields and a Submit button.

Once the user enters the credentials and hit Submit, I need to make a request to the server to generate a JWT token(which I'm getting using an HttpClient) for the validated user.

And then This token should be sent via form-data to a web page and the response page should be loaded in a WebView.

Is this possible in Xamarin.forms? If yes how can it be done?

1
Did you solve your issue? - Lucas Zhang - MSFT
Yes Lucas, In my scenario the web page returns a 302 (redirect) status. Therefore I had to use an HttpWebRequest to make the POST request by disabling AllowAutoRedirect. - Dushani Gunawardena

1 Answers

0
votes

Is this possible in Xamarin.forms?

Yes, you can use HttpClient

HttpClient client = new HttpClient() { Timeout = TimeSpan.FromSeconds(30) };

HttpContent content = new StringContent(JsonConvert.SerializeObject(objectToPost), Encoding.UTF8, "application/x-www-form-urlencoded");

var response = await client.PostAsync(new Uri("http://your.url"), content);

if (response.IsSuccessStatusCode) {
    var responseFromServer = await response.Content.ReadAsStringAsync();
}
else {
    // handle errors
}