Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Convert String to XML (WEB API) Android Xamarin

Xammy10Xammy10 Member ✭✭✭

I already figured out how to post data on the web api, but the data is not posting, i know that the codes are right but the conversion of text might be wrong (Correct me if I'm wrong)-

This is my Main Acticity

using Android.App;
using Android.Widget;
using Android.OS;
using System;
using System.Net.Http;
using Newtonsoft.Json;
using System.Text;

namespace PostRequest
[Activity(Label = "PostRequest", MainLauncher = true)]
public class MainActivity : Activity
Button savebtn;
protected override void OnCreate(Bundle savedInstanceState)

        // Set our view from the "main" layout resource
        savebtn = FindViewById<Button>(Resource.Id.click_meh);

        savebtn.Click += async delegate
            using (var client = new HttpClient())
                //new post
                var post = new visitorsmodel
                    ID = 1,
                    lname = "Square Pants",
                    fname = "Sponge",
                    mname = "Arenas",
                    school = "BOB",
                    email = "[email protected]",
                    num = "0909090909"
                // create the request content and define Json
                var json = JsonConvert.SerializeObject(post);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                // send a POST request
                var uri = "";
                var results = await client.PostAsync(uri, content);


                ////Getting results
                //var resultsString = await results.Content.ReadAsStringAsync();
                //var display = JsonConvert.DeserializeObject<info>(resultsString);


When i click the "CLICK MEH" button, the data will post on the Web API (As i know)

and here is my class model:

namespace PostRequest
public class visitorsmodel
public int ID { get; set; }
public string lname { get; set; }
public string fname { get; set; }
public string mname { get; set; }
public string school { get; set; }
public string email { get; set; }
public string num { get; set; }

    public override string ToString()
        return string.Format(
            "Post ID: {0}\nlname: {1}\nfname: {2}mname: {3}school: {4}email: {5}num:",
            ID, lname, fname, mname, school, email, num);



**But there's no changes in the Web API that i create using WPF self host.

This is my WEB API**

why i can't post in this web API (XML)?

Thanks in advance :)

Best Answer


Sign In or Register to comment.