How to make a post request using Restsharp and pass values as formdata or json?

  • 1 Answers
Restsharp is a very popular Http Client library for dotnet by which you can easily do request and response type detection. Here is the example of using Restsharp for making a post request and passing data either by Json values or form data :

We need to install Restsharp library using Nuget Package manager :

//use the library
using RestSharp;

//code to do the request

var client = new RestClient("");
var request = new RestRequest("/test-submit.php", Method.POST);

//when we have to send json data
//request.RequestFormat = DataFormat.Json;
//request.AddJsonBody(new Formvalue
//    name = "testname",
//    email = "",
//    phone = "98889898",
//    company = "testcompany"

//when we have to send formdata
request.AddParameter("name", "testname");
request.AddParameter("email", "  ");
request.AddParameter("phone", "999999999");
request.AddParameter("company", "testcompany");

  • 0
  • 0

©2020 Edukot | Terms | Privacy | About