I am using the Grapevine server in a console application.Calls via get work perfectly.
Now I want to pass a serialized order object to an endpoint via post request, but I get the following error message:
Sent 0 request content bytes, but Content-Length promised 538
Server code (empty body):
[RestResource] public class OrderService { public OrderService() { } [RestRoute(HttpMethod = HttpMethod.POST, PathInfo = "/distribution/saveorder")] public IHttpContext SaveOrder(IHttpContext context) { return context; }}
Client code:
public void Test() { RestClient client = new RestClient(); client.Host = "localhost"; client.Port = 8120; RestRequest request = new RestRequest("/distribution/saveorder"); request.HttpMethod = HttpMethod.POST; request.ContentType = ContentType.JSON; Order order = new (); order.Buyer.Number = "4711"; OrderItem item = new (); item.Article.Number = "1111111"; item.Quantity = 5; order.Items.Add (item); item = new (); item.Article.Number = "2222222"; item.Quantity = 20; request.Payload = JsonSerializer.Serialize(order); request.ContentLength = request.Payload.Length; var response = client.Execute(request);}
The error message is pretty clear, but where / how do I enter the content length - or am I using the payload incorrectly?