[closed] Call Tour API with C# and RestSharp return empty content


I have an application that uses the * tour * API to optimize my journey. In the beginning it worked very well but now the result of the API call * tour * is empty content.

I haven’t changed anything from the initial code.

This is my code in C# to call the tour API (I use RestSharp)
public class LocationRouteXl
public String name { get; set; }
public String lat { get; set; }
public String lng { get; set; }
public Int32 servicetime { get; set; }

var list = new List<LocationRouteXl>()
new LocationRouteXl() { lat="41.901202", lng="12.499968", name="Start", servicetime=0 }, 
new LocationRouteXl() { lat="41.901571", lng="12.459103", name="49491", servicetime=60 },
new LocationRouteXl() { lat="41.901202", lng="12.499968", name="End", servicetime=0 }
String json = JsonConvert.SerializeObject(list);
RestRequest request = new RestRequest("tour", Method.POST);
request.AddHeader("Authorization", "Basic " + auth);
request.AddHeader("Accept", @"application\json");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");

request.AddParameter("locations", json, ParameterType.GetOrPost);
IRestResponse response = client.Execute(request);

The problem is that response.Content is always empty and response.ErrorMessage is ‘Underlying connection closed: Unexpected error during a send operation’.

I tried also with postman and is working well, i tred also the code that automatically generate for C# and restsharp

var client = new RestClient(“https://api.routexl.com/tour”);
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader(“Authorization”, “Basic xxx”);
request.AddHeader(“Content-Type”, “application/x-www-form-urlencoded”);
request.AddHeader(“Content-Type”, “multipart/form-data; boundary=--------------------------219123338859153648958175”);
request.AlwaysMultipartFormData = true;
request.AddParameter(“locations”, “[{“name”:“Start”,“lat”:“41.901202”,“lng”:“12.499968”,“servicetime”:0,“restrictions”:null},{“name”:“49390”,“lat”:“41.901571”,“lng”:“12.459103”,“servicetime”:60,“restrictions”:null},{“name”:“End”,“lat”:“41.901202”,“lng”:“12.499968”,“servicetime”:0,“restrictions”:null}]”);
IRestResponse response = client.Execute(request);

But return always empty string as content.

Any help?
Thank you

I solved it by setting .net 4.6 in the project.

1 Like