2014-09-18 104 views
1

我能夠使用System.Web.HttpClient像這樣用字符串參數發送POST請求的URL的URL:與字符串參數發送POST請求使用Windows.Web.HttpClient PostAsync()

// Create the HTTPClient 
HttpClient httpClient = new HttpClient(); 

// Add string parameters 
FormUrlEncodedContent content = new FormUrlEncodedContent(new[] { 
    new KeyValuePair<string, string>("client_id", "myclientid), 
    new KeyValuePair<string, string>("serial_number", "myserialnumber) 
}); 

// Make the call 
HttpResponseMessage response = await httpClient.PostAsync(_requestUri, content); 

然而,我想要做同樣的事情,但是與Windows.Web.HttpClient類。
主要區別在於PostAsync方法接受HttpContent作爲第二個參數,所以我的FormUrlEncodedContent不起作用。另外我無法創建帶有JSON的IHttpContent,因爲我需要傳遞字符串參數。

有什麼想法?

回答