我正在调用一个返回json 的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来获得响应。
您应该将其包含在您的帖子请求中:
StringContent stringContent = new StringContent(data_json, UnicodeEncoding.UTF8, "application/json");
var result = client.PostAsync(uri, stringContent).Result;