Can't get it to work: C# Console App Refreshing ESI Token

I could use some help please. I am trying to create a C# console app that gets an access key from a refresh token. Obviously my end program does far more, but I’m stuck here. I obtained the refresh key from postman, so this is my first attempt to use c# to interact with EvE ESI. Here is my code:

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
    class Program
        static HttpClient client = new HttpClient();

        static async Task RunAsync()
            string clientid = "<<client_id>>";
            string secret = "<<secret>>";
            string auth_header = $"{clientid}:{secret}";
            string auth_header_64 = $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes(auth_header))}";
            string refreshtoken = "<<refresh Token>>";

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
            client.DefaultRequestHeaders.Add("Authorization", auth_header_64);

            HttpResponseMessage response;
                response = await client.GetAsync($"{refreshtoken}");
                if (!response.IsSuccessStatusCode)
                    Console.WriteLine("Error refreshing token");
                string data = await response.Content.ReadAsStringAsync();

            catch (Exception e)

        static void Main(string[] args)

Here is the response that I am getting:

Error refreshing token
StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent, Headers:
  Cache-Control: private
  Server: Microsoft-IIS/10.0
  Date: Mon, 22 Apr 2019 03:19:24 GMT
  Content-Type: text/html
  Content-Length: 0

Thank you in advance for your help.

Are you sure you’re using the right ESI url? Last I was told it was, but you appear to be using, which is the URL for the SSO service rather than ESI.

I’m not sure why you’re getting the error, but, you’re if you’re not getting a json errors back, you’re most likely not sending everything you need to send or sending it to the wrong place, SSO should be returning json errors on failure.

I will also strongly suggest that you use a library instead of reinventing the wheel:

In case you insist on doing it yourself, then SSO is documented in the ESI docs:

1 Like

You can look here for a working example:

Line 215 RefreshToken() method

1 Like

@ParaPants I don’t’ fully know C#, however it seems you are doing a GET request, when it should be POST request?

The request should be a POST with x-www-form-urlencoded data as the POST body.


Content-Type: application/x-www-form-urlencoded
Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l  


@Qia_Kare is the base URL for ESI. When dealing with the SSO flow, is the correct host since he is trying to refresh a token.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.