1
I am making an application using Xamarin Native and I decided to use Restsharp to make the requests to my API, the problem is that the first request made takes a few seconds (some 3) to be made, while the others go fast (question of ms). I have tried several "cool" from the international community but none worked, follow the code of my constructor:
public RestApi(IPresenter presenter)
{
#if DEBUG
_server = "http://192.168.29.3";
#endif
_client = new RestClient(_server);
_client.Proxy = null;
HttpWebRequest.DefaultWebProxy = null;
WebRequest.DefaultWebProxy = null;
ServicePointManager.UseNagleAlgorithm = false;
_presenter = presenter;
}
The call to the api is being carried out asynchronously as follows:
var request = new RestRequest(url, method, DataFormat.Json);
_client.ExecuteAsync(request, back => _presenter.HandleData(back));
*NOTE: It’s no problem in the API because the old app, made in java, works normally.
You have already made the request in hand ... with Webrequest to see if there is a difference?
– novic
I didn’t do it, I just did it for Java like I said and it was good. To get around the problem I made a request "ping-pong", but I know there is a "correct" way to solve this.
– Paulo Victor
The right way is to do webrequest ... because that way you’re doing it for a third party.package. Your question should have a minimum and functional.example to check the problems
– novic
I managed to improve the response time a little by configuring Unsafeauthenticatedconnectionsharing from Restclient to true.
_client.UnsafeAuthenticatedConnectionSharing = true;
– Paulo Victor
I made a simple client using Httpclient and got much faster...
– Paulo Victor