Neo
Neo

Reputation: 16239

.NET core azure function app restsharp restclient throw The SSL connection could not be established

I have .net core azure function app ,

below code was working fine till date.

Now i'm getting this error -

The SSL connection could not be established, see inner exception. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

var client = new RestClient("https://test.salesforce.com/services/oauth2/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.Parameters.Clear();
request.AddParameter("grant_type", "password");
request.AddParameter("username", "user");
request.AddParameter("password", "123");
request.AddParameter("client_id", "qw2");
request.AddParameter("client_secret", "23s");
response = client.Execute(request);

Upvotes: 0

Views: 707

Answers (2)

Hari Lakkakula
Hari Lakkakula

Reputation: 307

Add this before Execute the Rest

System.Net.ServicePointManager.Expect100Continue = false;

If Still Getting Error pass the Authentication Differently,Below auth is Basic,if you want bearer change the Auth type.

 client.Authenticator = new HttpBasicAuthenticator(Username), (Password);

Upvotes: 0

Joy Wang
Joy Wang

Reputation: 42133

Just add @Neo's comment as an answer to help the community members:

We need to add ipaddres range into salesforce to solve this problem.

Upvotes: 0

Related Questions