How to properly close a JSON Post using RestSharp?

  • Thread starter Thread starter mlong219
  • Start date Start date
M

mlong219

Guest
Hi All,

I'm trying to write a json POST message using .NET 4.5, with VS 2015.

The following code is able to post the message successfully, but for some odd reason, about (1) minute after the code executes, and closes. The server that received the message, will get a crash alert, and shutdown the message service.

I tried placing a sleep statement at the end of my code for 2 minutes, and that does give the server time to abort the connection, without taking down the service. I also checked the ServicePointManager, RestClient, and IResponse classes, and I dont see a Close, or Dispose method I can use to close the connection on my end. Any idea how I can close my application successfully without taken down the server services?


using RestSharp;
using RestSharp.Authenticators;
using Newtonsoft.Json;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var client = new RestClient("https://testdev.com:5109/Test");

var request = new RestRequest();
request.Method = Method.POST;
request.AddParameter("application/json", json, ParameterType.RequestBody);
request.RequestFormat = DataFormat.Json;
IRestResponse response = client.Execute(request);



Thanks!

Continue reading...
 
Back
Top