0

I came across a problem that would very much appreciate your help apron on. I'm trying to execute a curl command in my C# application and I get the response result witch is the header itself but the Json content that I actually need is missing in the output. Can't seem to figure out why the actual content of Json string is missing in the output. If i execute the curl command by hand I receive the json content with no problem.

What am I missing out ?

Code reference provided bellow

            using (var httpClient = new HttpClient())
        {
            using (var request = new HttpRequestMessage(new HttpMethod("POST"), "http://10.10.100.11:8080/ords/krauta/oauth/token"))
            {
                var base64Authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("Bam1EfR6yasT1pJlhOzJmQ..:T6SnqCHsa90dm6wu_l3-2g.."));
                request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64Authorization}");
                request.Content = new StringContent("grant_type=client_credentials", Encoding.UTF8, "application/x-www-form-urlencoded");
                var response =  httpClient.SendAsync(request);
                Console.Write(response.Result);

            }
        }

enter image description here

dmxyler
  • 79
  • 1
  • 1
  • 14

1 Answers1

0

Answer to the problem was found by the help of Joe. Here is the code bellow if anyone needs a reference in the future.

    private static  async Task GetAsyncToken()
    {
        using (var httpClient = new HttpClient())
        {
            using (var request = new HttpRequestMessage(new HttpMethod("POST"), "http://10.10.100.11:8080/ords/krauta/oauth/token"))
            {
                var base64Authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("Bam1EfR6yasT1pJlhOzJmQ..:T6SnqCHsa90dm6wu_l3-2g.."));
                request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64Authorization}");

                request.Content = new StringContent("grant_type=client_credentials", Encoding.UTF8,  "application/x-www-form-urlencoded");

                var response = await httpClient.SendAsync(request);
                var result = await response.Content.ReadAsStringAsync();
                var parseTokenValue = ParseToken.FromJson(result);
                _tokenValue =  parseTokenValue.AccessToken;


            }
        }
    }
dmxyler
  • 79
  • 1
  • 1
  • 14