I have created a api request to post form data to create a lead in salesforce.

First I requested authorization key to insert data to salesforce (Using oauth,client id and client secret.)

This works locally and data successfully posted in salesforce. Next I moved this code to UAT server. In that UAT server I'm not able to get the authorization key and data is not posting to salesforce

Below I attched the error in LOG file

techonlogy I used : C# MVC

local server : our server (my company)

uat server : client server

 //Function to Get Authorization
        public static string GetAuthorizationKey(ApiAuthorizeModel apiAuthorizeModel)
                string jsonResponse = string.Empty;
                string AuthToken = string.Empty;
                string Error = string.Empty;
                string ErrorDescription = string.Empty;

                if (!string.IsNullOrEmpty(apiAuthorizeModel.ClientID) && !string.IsNullOrEmpty(apiAuthorizeModel.ClientSecret) && !string.IsNullOrEmpty(apiAuthorizeModel.UserName) && !string.IsNullOrEmpty(apiAuthorizeModel.Password) && !string.IsNullOrEmpty(apiAuthorizeModel.TokenURI))
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                    using (var client = new HttpClient())
                        var request = new FormUrlEncodedContent(new Dictionary<string, string>{
                {ApiConstants.Grant_type, ApiConstants.Password},
                {ApiConstants.Client_secret, apiAuthorizeModel.ClientSecret},
                {ApiConstants.Username, apiAuthorizeModel.UserName},
                {ApiConstants.Password, apiAuthorizeModel.Password}

                        request.Headers.Add("X-PrettyPrint", "1");
                        var response = client.PostAsync(apiAuthorizeModel.TokenURI, request).Result;
                        jsonResponse = response.Content.ReadAsStringAsync().Result;
                    JObject jObject = JObject.Parse(jsonResponse);
                    Error = (string)jObject[ApiConstants.error];
                    ErrorDescription = (string)jObject[ApiConstants.error_description];
                    if (string.IsNullOrEmpty(Error))
                        AuthToken = (string)jObject[ApiConstants.AccessToken];
                        Log.Error(Error, typeof(SendDataToApi));
                        Log.Error(ErrorDescription, typeof(SendDataToApi));
                        isAPIErrorFlag = true;
                return AuthToken;
            catch (Exception e)
                Log.Error("Method : GetAuthorizationKey :", e, typeof(SendDataToApi));
                Log.Error(string.Concat("GetAuthorizationKey: ", e.Message.ToString()), typeof(SendDataToApi));
                return null;
2656 18:37:22 INFO  Method : GetAuthorizationKey:System.AggregateException: One or more errors occurred. 
System.Net.Http.HttpRequestException: An error occurred while sending the request.
---System.Net.WebException: Unable to connect to the remote server 
---System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond 
after a period of time, or established connection failed because connected host has failed to respond    at
System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult)
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)   
at System.Net.ServicePoint.ConnectSocketInternal(Boolean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress&
address, ConnectSocketState state, IAsyncResult asyncResult,
Exception& exception)
  • Can you share more about: - what technology do you use to connect to Salesforce? - what is the difference between "locally" (e.g. you wrote it works locally) and "UAT server"? I cannot yet see how this is related to Salesforce, i'd suspect some different network environment where your UAT server is located and some necessity to configure the client to adopt to that network environment. Sep 23, 2019 at 8:46
  • added in the question. what else you needed
    – Rajasekar
    Sep 23, 2019 at 8:56
  • 1
    Can you connect from the UAT server to Salesforce at all? Do they maybe require an outgoing HTTP proxy? Sep 23, 2019 at 8:59
  • 1
    Your UAT server is allowed to hit only some specefic IP address. Please work with IT team to whitelist these Salesforce IP addresses: help.salesforce.com/…
    – Ayub
    Sep 25, 2019 at 0:37
  • 1
    @Rajasekar That page says: Our recommended best practice is to whitelist our entire list of IP ranges. However, if you choose to only whitelist a subset of our list of IP ranges, you must do so according to the instructions below in order to avoid unintended service disruptions. As a global company, we distribute our provisioned IP ranges across our infrastructure; therefore, certain regions may have ranges from multiple Regional Internet Registries (i.e. RIPE, ARIN, APNIC).
    – SeanGorman
    Sep 26, 2019 at 14:05

2 Answers 2


Here's a few pointers to look at:

  1. Make sure your endpoint is set to: https://test.salesforce.com/services/oauth2/token
  2. Make sure your server is using the right TLS version as TLS v1.1 is disabled: https://help.salesforce.com/articleView?id=000221207
  3. Make sure your 'grant_type' attribute is set to 'password' - although if this were wrong, you should get a different error than you're getting
  • 1. end pointed I pointed : <setting name="tokenURI" value="test.salesforce.com/services/oauth2/token" /> 3. grant_type is set to password only 2. i'm using ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
    – Rajasekar
    Sep 23, 2019 at 10:50
  • I followed all of the above. I suspect this is due to network won't able to reach salesforce. Do i need to do anything to be configured in the network before accessing to the salesforce
    – Rajasekar
    Sep 23, 2019 at 10:54
  • 2
    That is a question that hopefully a person responsible for the UAT server at your client can tell you. Connectivity to Salesforce is similar to connectivity to any other public internet site. If they - your client - require an outgoing proxy or some firewall settings then they should be able to tell you. Sep 23, 2019 at 12:59
  • help.salesforce.com/… Do I need to white list all these IP's ?
    – Rajasekar
    Sep 26, 2019 at 11:41

Thanks for all your valuable comments. I have used this information to establish connectivity between your CRM servers and proxy server.

Depending on your environment, configure the server to allow traffic through the proxy at the machine.config or server’s root web.config (IIS level).

            <proxy usesystemdefault = "false" proxyaddress="http://ip address:port" bypassonlocal="false"/> 

It solves my problem. The below site that i refered


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .