I am using RestSharp on Xamarin to communicate with WebAPI using POST. I can send something and get a response but the outcome wasn't what I expected.
This is my code on Xamarin.
var request = new RestSharp.RestRequest ("api/device/stats", RestSharp.Method.POST);
request.AddHeader ("Content-Type", "application/json; charset=utf-8");
request.RequestFormat = DataFormat.Json;
request.AddBody(new AppUsageInfo {MAC = "ASDF"});
RestSharp.IRestResponse response = client.Execute (request);
var content = response.Content;
On my WebAPI :
public string Post([FromUri]UsageLogModel usageState)
{
//LogFunction.AddUsageLogs(usageState);
if (usageState.MAC == null)
return "fail";
else
return "success";
}
UsageLogModel is :
public class UsageLogModel
{
public string MAC;
}
Somehow the response is "Fail" which MAC is null. I scratched my head but have no idea what is going on.-
AppUsageInfois different from the one you're expecting in you post methodUsageLogModel