【问题标题】:Using Rest Service passing json c# [duplicate]使用传递json c#的Rest Service [重复]
【发布时间】:2016-11-30 11:48:42
【问题描述】:

我正在调用一个返回 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 来获得响应。

【问题讨论】:

  • 在帖子正文中传递?

标签: c# json rest json.net


【解决方案1】:

您应该将其包含在您的发布请求中:

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

【讨论】:

    猜你喜欢
    • 2011-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 2018-03-09
    • 2014-09-17
    • 1970-01-01
    相关资源
    最近更新 更多