在通用窗口应用程序中发布json值和参数
示例:
交 http://sampleurl?param=1¶m2=1 json body:[{" key":" value"," key2":" value2"}]
答案 0 :(得分:0)
我们可以将参数创建为字典并将其发布为formcontent
public static async Task<string> postdataAsync(Uri posturl, Dictionary<string, string> pairs)
{
string response = "";
try
{
var filter = new HttpBaseProtocolFilter();
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired);
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName);
HttpClient httpClient = new HttpClient(filter);
Windows.Web.Http.HttpFormUrlEncodedContent formContent = new Windows.Web.Http.HttpFormUrlEncodedContent(pairs);
HttpResponseMessage httpresponse = await httpClient.PostAsync(posturl, formContent);
response = await httpresponse.Content.ReadAsStringAsync();
}
catch
{
return null;
}
return response;
}