1

I'm calling a REST service that returns json

this is what I have so far

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;

Now, how do I use data_json? I need to pass the json to get the response.

Jim Hewitt
  • 1,726
  • 4
  • 24
  • 26
Carlos Anez
  • 61
  • 1
  • 11

1 Answers1

1

You should include it in your post request:

StringContent stringContent = new StringContent(data_json, UnicodeEncoding.UTF8, "application/json");
var result = client.PostAsync(uri, stringContent).Result;
Henrique Forlani
  • 1,325
  • 9
  • 22