0

Getting Following issue while authenticate salesforce using C#:

The remote server returned an error: (401) Unauthorized.

My code:

var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://ap8.salesforce.com/services/data/v37.0/sobjects/Account");
httpWebRequest.Method = "GET";
httpWebRequest.Accept = "application/Json";
httpWebRequest.Headers.Add("Authorization", "Bearer 6Cel800D0o0000018EWH8880o0000019quiPSXZfGP3CizqogLL0BhkN4ZhMPuqN0EuObUlmQPRszCqFkkQlhQ09U8r8XXXXXXXXX");
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Console.WriteLine("Response" + httpResponse);
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
    var result = streamReader.ReadToEnd();
}

Please help me out from this?

3
  • Please use relevant tags. It's not clear how this question relates to salesforce1-app, salesforcedx, or salesforce-id, which is why I originally removed the first one from the question.
    – David Reed
    Mar 18, 2019 at 12:07
  • Whats the instance url you get from login call Mar 18, 2019 at 16:11
  • Hi. This appears very similar to the sample sample code that Salesforce provides. developer.salesforce.com/page/… You might want to try that code in case there are some slight differences. Otherwise, verify that your access token and server URL are valid. Mar 20, 2019 at 13:37

1 Answer 1

-1

You have your password + token in the wrong order. Use it as the following (without blank spaces and <>.):

<password><token>

You must log in to answer this question.

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