2017-02-18 13 views
1

PostAsyncのアプリケーションでHttpFormUrlEncodedContentオブジェクトを使用しています。HttpFormUrlEncodedContentはsystem.Net.Httpの一部ではありません

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Data; 
using System.Text; 
using System.Data.SqlClient; 
using System.Configuration; 
using System.Threading.Tasks; 
using System.Security.Cryptography; 
using Newtonsoft.Json; 
using System.Net; 
using System.Net.Http; 

次は私のポストを行うためのコードです:

タイプ:

var client = new HttpClient(); 
var values = new List<KeyValuePair<string, string>>(); 
values.Add(new KeyValuePair<string, string>("task", task)); 
values.Add(new KeyValuePair<string, string>("merchant", "2234-6566")); 
values.Add(new KeyValuePair<string, string>("ref", refl)); 
values.Add(new KeyValuePair<string, string>("hash", hash)); 
values.Add(new KeyValuePair<string, string>("amount", "20")); 
values.Add(new KeyValuePair<string, string>("seller", "[email protected]")); 
values.Add(new KeyValuePair<string, string>("remarks", "payment")); 

HttpFormUrlEncodedContent formContent = new HttpFormUrlEncodedContent(values); 

var content = new FormUrlEncodedContent(values); 
Task<HttpResponseMessage> t = client.PostAsync("https://epay.com/api/", content); 
t.Wait(); 
var response = t.Result; 

はこれで私は以下のようにエラーメッセージが表示されますよう は、私はすべての必要な基準を置きますまたは名前空間名 'HttpFormUrlEncodedContent'を にできませんでした(使用するディレクティブまたはアセンブリ参照がありませんか)

この問題を解決するにはどうすればよいですか?

+0

に値のコレクションを追加UWPアプリケーションのための 'Windows .Web .Http'からのものです。 – Nkosi

答えて

0

これは、HttpFormUrlEncodedContent ClassがUWPアプリケーション用のWindows​.Web​.Http名前空間であるためです。

プログラムが実際にUWPアプリケーションである場合は、必要なアセンブリが参照されていることを確認し、その名前空間にusingを追加します。

そうでないという理由だけで[HttpFormUrlEncodedContentクラス](https://docs.microsoft.com/en-us/uwp/api/Windows.Web.Http.HttpFormUrlEncodedContent)であるFormUrlEncodedContent Constructor

関連する問題