1

I'm having difficulty putting together a request by sending a json content, can not find anything in the 4.x documentation it's completely different from version 3.x

RestClient client = new RestClient();
client.Host = "localhost";
client.Port = 8080;

RestRequest request = new Grapevine.Client.RestRequest("/route1");
request.HttpMethod = HttpMethod.POST; 

RestResponse response = client.Execute(request) as RestResponse;
Elvis Reis
  • 155
  • 4
  • 12
  • I don't see any place in here where you are adding anything to the payload (putting content in the body of the request). Did you miss a step? – Scott Offen Mar 27 '17 at 16:45

1 Answers1

1

Somewhere in your code - prior to sending your request - you need to set the body (or payload) of your request.

request.Payload = "send this data";

The payload is just a string, so it's up to you to serialize your objects to a JSON string before making the assignment (and set the ContentType property appropriately). The Json.NET library is widely used to accomplish this. You can also do this by hand:

request.ContentType = ContentType.JSON;
request.Payload = "{\"key\":\"value\"}";
Scott Offen
  • 6,933
  • 3
  • 21
  • 24
  • FWIW, at least this part of the 3.x documentation should still be relevant. https://github.com/sukona/Grapevine/wiki/Getting-Started-RestClient-3.x#other-request-properties – Scott Offen Mar 27 '17 at 17:05