2016-07-26 60 views
1

我打電話,返回JSON使用REST服務傳遞JSON C#

REST服務這是我迄今爲止

HttpClient client = CreateClient(this.url, this.username, this.password); 
string data_json = Newtonsoft.Json.JsonConvert.SerializeObject(Detail, Newtonsoft.Json.Formatting.Indented); 
//Detail is a class with the json data 
HttpResponseMessage response = client.GetAsync(uri).Result; 
result = response.Content.ReadAsStringAsync().Result; 

現在,我該如何使用data_json?我需要通過json來獲得響應。

+0

通在後的身體嗎? – Steve

回答

1

你應該包括在您的POST請求:

StringContent stringContent = new StringContent(data_json, UnicodeEncoding.UTF8, "application/json"); 
var result = client.PostAsync(uri, stringContent).Result;