我为UWP撰写应用程序。
我有这段代码
private List<RootObject> ordersList;
public List<RootObject> OrdersList
{
get { return ordersList; }
set
{
ordersList = value;
OnPropertyChanged();
}
}
private RootObject ordersChange;
public RootObject OrdersChange
{
get { return ordersChange; }
set
{
ordersChange = value;
OnPropertyChanged();
}
}
当我点击按钮值时,请写入ordersChange
和set
以进行评估。
我需要获取价值,序列化并通过邮寄请求发送。
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(@"http://api.simplegames.com.ua");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("utf-8"));
string endpoint = @"/post_from_local.php";
try
{
HttpContent content = new StringContent(JsonConvert.SerializeObject(*****), Encoding.UTF8, "application/json");
HttpResponseMessage response = await httpClient.PostAsync(endpoint, content);
***
的价值所在。我怎么能这样做?
感谢您的帮助。
答案 0 :(得分:1)
如果你想发布OrdersChange,你可以这样做。
var json = JsonConvert.SerializeObject(viewModelInstance.OrdersChange);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(apiUrl, content);