Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

How to do a POST request with JSON

$
0
0

I'm using the Microsoft.Net.Http package in Xamarin Forms PCL. It is sending the request, but it isn't sending it as "applicaiton/json" it's sending it as "text/html" still. I've looked online and I haven't found anything that works. I did find PostAsJsonAsync, but Xamarin tells me this method isn't found. Anyone have any idea how to make this work?

My code:
`string sData = Newtonsoft.Json.JsonConvert.SerializeObject(myObject);

            HttpContent content = new System.Net.Http.StringContent(sData, System.Text.Encoding.UTF8,  "application/json");

            client.BaseAddress = new Uri("http://mysite.com/api/v1/");

            var response = await client.PostAsync("my_page", content);

            var responseJson = response.Content.ReadAsStringAsync().Result;`

As @MihaMarkic pointed out, I didn't explain the situation very well. I've edited my description to have more info.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>