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