title: How to send json Data using RestSharp POST Method in c#
body: <p>im going to test REST API using RestSharp and required post method to post data and base on callback give status (error,invalid,success) im geting INVALID that is "Object reference not set to an instance of an object" <a href="https://i.stack.imgur.com/FaB46.png" rel="nofollow noreferrer">getting json data from header see image</a></p>
  
  <p>this is my TestMethod </p>
  
  <pre><code>     [TestMethod()]
              public void AddNewBFormat()
              {
              Random r = new Random((int)DateTime.Now.Ticks);
              var x = r.Next(100000, 999999);
              string s = x.ToString("000000");
  
              string UniqueFileName = "S" + s + DateTime.Now.ToString("yyyyMMdd") + ".xlsx";
              request.Resource = "api/BFormat/AddNewBFormat";
              request.Method = Method.POST;
              var body= "{'UploadFileVM':{'BordereauxId':null,'BFormatId':null,'FileName':'"+UniqueFileName+ "','Filesize':0,'Path':'C:\\Applications\\new\\\\TempUploadedFiles','size':0,'ActiveSheetIndex':0,'HeaderIndex':0,'MultiHeaders':null,'SheetNames':null,'IsPasswordProtected':false},'BFormat':{'UniqueFileName':'"+ UniqueFileName+"'}}";
              request.RequestFormat = DataFormat.Json;
              request.AddHeader("Content-type", "application/json");
              request.AddParameter("Application/Json", body, ParameterType.RequestBody);
              var queryResult = client.Execute&lt;ResponseData&lt;Guid&gt;&gt; (request).Data;
              try
              {
                  Assert.IsTrue(queryResult.ReturnData != null);
  
              }
              catch (Exception ex)
              {
                  Assert.Fail(ex.Message);
              }
              }
  </code></pre>
  
  <p>i have tried <code>request.addJsonBody</code> also but same result i want to know to send json data using POST Method </p>