-1
在通用的Windows应用程序的参数一起发布JSON值我怎样才能在窗口张贴JSON字符串与一些参数一起普遍应用C#
例如:
交 http://sampleurl?param=1¶m2=1 JSON体:[{”关键 “:” 值”, “KEY2”: “值2”}]
在通用的Windows应用程序的参数一起发布JSON值我怎样才能在窗口张贴JSON字符串与一些参数一起普遍应用C#
例如:
交 http://sampleurl?param=1¶m2=1 JSON体:[{”关键 “:” 值”, “KEY2”: “值2”}]
,我们可以创建参数词典,并张贴作为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;
}
问题是什么?使用HttpClient或构建URI或构建JSON? –
请提出答案,以便其他人更喜欢它 –