post a json value along with parameters in universal windows application
example:
post http://sampleurl?param=1¶m2=1 json body : [{"key":"value","key2":"value2"}]
we can create the parameters as dictionary and post it as 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;
}