How to send Raw Json using RestSharp?

I have an endpoint that accepts a Json object that has a message element, and the rest can have different properties. Here is an example:

public void SendMessage(IDictionary<string, string> message) { var client = new RestClient(MahUrl); var request = new RestRequest(Method.POST); var json = new JObject(); foreach (var pair in message) { json.Add(pair.Key, pair.Value); } json = new JObject(new JProperty("message", json)); // { // "message": // { // "prop1": "val1", // "foo": "bar", // "batman": "robin" // } // } // not quite sure here request.? // send request } 

I have seen many examples of how you can serialize / deserialize a .Net object, but as you can see, the properties of the json object can be anything. How can I just send raw json using RestSharp?

+6
source share
1 answer

I believe the following snippet is what you are looking for.

 request.AddParameter("application/json", json, ParameterType.RequestBody); 
+6
source

Source: https://habr.com/ru/post/925046/


All Articles