0

I'm attempting to use RestSharpe.NetCore(v.105.2.3.0) to make a GET request e.g. https://pokeapi.co/api/v2/pokemon/ditto in C#.

However, I get a Error: SecureChannelFailure (Unable to read data from the transport connection: Connection reset by peer.) error with my code below.

IRestClient _client;

protected override async void OnCreate(Bundle bundle)
{
    ...
    var baseurl = "https://pokeapi.co/api/v2/pokemon/";
    var apiMethod = "ditto";
    var request = new RestRequest(apiMethod, Method.GET);

    this._client = new RestClient();
    this._client.BaseUrl = new Uri(baseurl);
    TaskCompletionSource<IRestResponse> taskCompletion = new TaskCompletionSource<IRestResponse>();
    var json = this._client.ExecuteAsync<object>(request, r => taskCompletion.SetResult(r));
    var response = (object)(await taskCompletion.Task);
}

Any ideas why and how to resolve this?

Bhav
  • 1,957
  • 7
  • 33
  • 66

1 Answers1

0

Add this line before making the connection to use TLS1.1 or 1.2 to connect to the site.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;

For proxy, add your proxy to the client

client.Proxy = new WebProxy("127.0.0.1", 8888);

See this link for details

Jawad
  • 11,028
  • 3
  • 24
  • 37