Xamarin.Forms make Http POST request using a webview












0















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?










share|improve this question

























  • 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
















0















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?










share|improve this question

























  • 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














0












0








0








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 8:39









Lucas Zhang - MSFT

2,1652210




2,1652210










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



















  • 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












1 Answer
1






active

oldest

votes


















0















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
}





share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0















    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
    }





    share|improve this answer




























      0















      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
      }





      share|improve this answer


























        0












        0








        0








        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
        }





        share|improve this answer














        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
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 3:02









        Lucas Zhang - MSFTLucas Zhang - MSFT

        2,1652210




        2,1652210
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Lugert, Oklahoma