0
votes

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);
2
Could you tell me if you can run the code on-premise? - Jim Xu
I found out this is because we need to add ipaddres range into salesforce to solve this problem once it is done let me chck again :) - Neo
Since your issue has been resolved, could you please post your answer? It may help more persons. - Jim Xu

2 Answers

0
votes

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.

0
votes

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);