I have a post method that sends json to my api.
My endpoint works in postman so my problem is in my xamarin post request:
async void RegisterUser(o
So after 2 days of googling i found a solution:
https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti#overview
now I can post to my api from my xamarin forms project!!!
thanks for everyone's input
Please test the Web Api with some REST testing tool like POSTMAN, to verify that it works with your JSON data firstly.
If your webapi have no problems, please take a look the following code, I can post data to asp.net core webapi successfully, and return value.
private async void btnpost_Clicked(object sender, EventArgs e)
{
ContactModel cm = new ContactModel() {ID=1,Name="cherry",Age=12 };
var httpClient = new HttpClient();
var content = JsonConvert.SerializeObject(cm);
HttpContent httpContent = new StringContent(content, Encoding.UTF8);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var uri = new Uri("http://xxx.xx.xx.xx:8088/api/Contact");
HttpResponseMessage response = await httpClient.PostAsync(uri, httpContent);
if (response.IsSuccessStatusCode)
{
var data = await response.Content.ReadAsStringAsync();
string ss = data;
}
}
Please note: Adding android:usesCleartextTraffic="true" in Mainfeast.xml,because starting with Android 9 (API level 28), cleartext support is disabled by default. if not, you may have Cleartext HTTP traffic not permitted error.