-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? –
請提出答案,以便其他人更喜歡它 –