2016-09-07 7 views
0

私はcomplexオブジェクトを受け取り、データベースに追加するWeb APIを持っています。HttpClientで使用する動的バインディングモデル

var myWidgit= new Widgit() { 
    Name = "WidgitName", 
    Price = 50, 
    Category = "Appliance" }; 

HttpResponseMessage response = client.PostAsync("api/createwidgit", myWidgit); 

私は、APIへの1つのオフの呼び出しを行う必要があると私はWidgitのための別のクラスファイルを作成しないようにしたいと思います。

Widgitクラスを定義し、それを使用するメソッドに値を割り当てる方法はありますか?このメソッドでちょうど使用されたdynamicクラスのような並べ替え。私はそれを考え出したと思う

答えて

0

...基本的に私が作成するために探していたdynamicオブジェクトは、より良い

をフォーマット申し訳ありませんが、私は把握することができませんでし
new StringContent(string.Format("Name={0}&Price={1}&Category={2}", HttpUtility.UrlEncode("WidgitName"), HttpUtility.UrlEncode(50)), HttpUtility.UrlEncode("Appliance"), Encoding.UTF8, 
    "application/x-www-form-urlencoded") 

を使用して達成される

HttpResponseMessage response = client.PostAsync("api/createwidgit", new StringContent(string.Format("Name={0}&Price={1}&Category={2}", HttpUtility.UrlEncode("WidgitName"), HttpUtility.UrlEncode(50), HttpUtility.UrlEncode("Appliance"), Encoding.UTF8, "application/x-www-form-urlencoded")); 

関連する問題