How to pass in a JSON payload for consuming a REST service.
Here is what I am trying:
var requestUrl = "http://example.org";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualifiedHeaderValue("application/json"));
var result = client.Post(requestUrl);
var content = result.Content.ReadAsString();
dynamic value = JsonValue.Parse(content);
string msg = String.Format("{0} {1}", value.SomeTest, value.AnotherTest);
return msg;
}
How do I pass something like this as a parameter to the request?:
{"SomeProp1":"abc","AnotherProp1":"123","NextProp2":"zyx"}
I got the answer from here: POSTing JsonObject With HttpClient From Web API
httpClient.Post(
myJsonString,
new StringContent(
myObject.ToString(),
Encoding.UTF8,
"application/json"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With