2016-07-26 55 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;