Asp.net core razor pages token request

I am using WebClient to make the request and keep getting a 401 error here is my code

    public void OnGet()
    {
        Code = Request.Query["code"];
        string username = "******";
        string password = "*********";
        using (var wc = new System.Net.WebClient())
        {
            string credentials = String.Format("{0}:{1}", username, password);
            byte[] bytes = Encoding.ASCII.GetBytes(credentials);
            string base64 = Convert.ToBase64String(bytes);
            string authorization = String.Concat("basic ", base64);
            string parameters = string.Concat("grant_type=", "authorization_code", "&code=", Code);
                string url = "https://login.eveonline.com/oauth/token?"+parameters;
            wc.Headers.Add("Authorization", authorization);
            wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            wc.Headers.Add("Host", "login.eveonline.com");
             string result = wc.UploadString(url, "");
            bodycode = result;
        }
    }

any ideas?

Are your really passing a username and password? Or are those just poorly named clientid and secret?

poorly named

I don’t know if it will make a difference, as, net is not my language, but, the request is meant to be post and you’re appending the values to the url (like a get request), but, they should be the second parameter of UploadString.

Something like:

 string url = "https://login.eveonline.com/oauth/token";

wc.UploadString(url, parameters);

Edit:
Again, disclaimer, I don’t know anything about asp.net.
However, there are some .NET libraries, you may or may not be able to use on eve awesome:
https://github.com/devfleet/awesome-eve#net

still get the 401 error

@shawn313 You prob just need to use Basic, notice the capital B, in your Authorization header.

that was it :triumph:

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