Epoc

http://stackoverflow.com/q/16768314/1252290

May 27th, 2013
3,310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. var request = new RestRequest("some/where", Method.POST); // Create a new request
  2.  
  3. request.RequestFormat = DataFormat.Json; // The request data is JSON
  4. request.AddBody(parameters); // parameters is a dictionnary object, so it is serialized as a JSON string by Restclient
  5. request.AddHeader("Content-Type", "application/json"); // Make sure that the request is detected as a JSON by the server
  6.  
  7. string body = request.Parameters.Find(param => param.Type == ParameterType.RequestBody).Value.ToString(); // Get the raw request body
  8.  
  9. request.Parameters.RemoveAll(param => param.Type == ParameterType.RequestBody); // Remove this body from the request
  10.  
  11. // Perform some operation to this raw body
  12.  
  13. // Adding back the modified body to the request
  14. request.RequestFormat = DataFormat.Json;
  15. request.AddParameter("application/json", body, ParameterType.RequestBody);
Advertisement
Add Comment
Please, Sign In to add comment