Xamarin.Forms make Http POST request using a webview
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?
webview xamarin.forms
add a comment |
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?
webview xamarin.forms
Did you solve your issue?
– Lucas Zhang - MSFT
Nov 16 '18 at 5:25
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
Nov 19 '18 at 11:43
add a comment |
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?
webview xamarin.forms
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?
webview xamarin.forms
webview xamarin.forms
edited Nov 15 '18 at 8:39
Lucas Zhang - MSFT
2,0152210
2,0152210
asked Nov 14 '18 at 10:38
Dushani GunawardenaDushani Gunawardena
32
32
Did you solve your issue?
– Lucas Zhang - MSFT
Nov 16 '18 at 5:25
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
Nov 19 '18 at 11:43
add a comment |
Did you solve your issue?
– Lucas Zhang - MSFT
Nov 16 '18 at 5:25
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
Nov 19 '18 at 11:43
Did you solve your issue?
– Lucas Zhang - MSFT
Nov 16 '18 at 5:25
Did you solve your issue?
– Lucas Zhang - MSFT
Nov 16 '18 at 5:25
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
Nov 19 '18 at 11:43
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
Nov 19 '18 at 11:43
add a comment |
1 Answer
1
active
oldest
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
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298218%2fxamarin-forms-make-http-post-request-using-a-webview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
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
add a comment |
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
add a comment |
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
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
answered Nov 15 '18 at 3:02
Lucas Zhang - MSFTLucas Zhang - MSFT
2,0152210
2,0152210
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53298218%2fxamarin-forms-make-http-post-request-using-a-webview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you solve your issue?
– Lucas Zhang - MSFT
Nov 16 '18 at 5:25
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
Nov 19 '18 at 11:43