Get json from curl command [duplicate]












0
















This question already has an answer here:




  • reading my json response from a post request i sent

    2 answers




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










share|improve this question













marked as duplicate by Community Nov 24 '18 at 14:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • You have to read the response's Content property.

    – Crowcoder
    Nov 24 '18 at 14:13











  • I have tried that as well I receive - System.Net.Http.StreamContent but no json text.

    – dmxyler
    Nov 24 '18 at 14:13






  • 1





    You should be calling await on the SendAsync call as well as the await response.Content.ReadAsStringAsync(); (which you're not currently doing) to get the content

    – Joe
    Nov 24 '18 at 14:15













  • Got it works fine. Thank you all !! :)

    – dmxyler
    Nov 24 '18 at 14:28
















0
















This question already has an answer here:




  • reading my json response from a post request i sent

    2 answers




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










share|improve this question













marked as duplicate by Community Nov 24 '18 at 14:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • You have to read the response's Content property.

    – Crowcoder
    Nov 24 '18 at 14:13











  • I have tried that as well I receive - System.Net.Http.StreamContent but no json text.

    – dmxyler
    Nov 24 '18 at 14:13






  • 1





    You should be calling await on the SendAsync call as well as the await response.Content.ReadAsStringAsync(); (which you're not currently doing) to get the content

    – Joe
    Nov 24 '18 at 14:15













  • Got it works fine. Thank you all !! :)

    – dmxyler
    Nov 24 '18 at 14:28














0












0








0









This question already has an answer here:




  • reading my json response from a post request i sent

    2 answers




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










share|improve this question















This question already has an answer here:




  • reading my json response from a post request i sent

    2 answers




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





This question already has an answer here:




  • reading my json response from a post request i sent

    2 answers








c# curl






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 14:08









dmxylerdmxyler

127




127




marked as duplicate by Community Nov 24 '18 at 14:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Community Nov 24 '18 at 14:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • You have to read the response's Content property.

    – Crowcoder
    Nov 24 '18 at 14:13











  • I have tried that as well I receive - System.Net.Http.StreamContent but no json text.

    – dmxyler
    Nov 24 '18 at 14:13






  • 1





    You should be calling await on the SendAsync call as well as the await response.Content.ReadAsStringAsync(); (which you're not currently doing) to get the content

    – Joe
    Nov 24 '18 at 14:15













  • Got it works fine. Thank you all !! :)

    – dmxyler
    Nov 24 '18 at 14:28



















  • You have to read the response's Content property.

    – Crowcoder
    Nov 24 '18 at 14:13











  • I have tried that as well I receive - System.Net.Http.StreamContent but no json text.

    – dmxyler
    Nov 24 '18 at 14:13






  • 1





    You should be calling await on the SendAsync call as well as the await response.Content.ReadAsStringAsync(); (which you're not currently doing) to get the content

    – Joe
    Nov 24 '18 at 14:15













  • Got it works fine. Thank you all !! :)

    – dmxyler
    Nov 24 '18 at 14:28

















You have to read the response's Content property.

– Crowcoder
Nov 24 '18 at 14:13





You have to read the response's Content property.

– Crowcoder
Nov 24 '18 at 14:13













I have tried that as well I receive - System.Net.Http.StreamContent but no json text.

– dmxyler
Nov 24 '18 at 14:13





I have tried that as well I receive - System.Net.Http.StreamContent but no json text.

– dmxyler
Nov 24 '18 at 14:13




1




1





You should be calling await on the SendAsync call as well as the await response.Content.ReadAsStringAsync(); (which you're not currently doing) to get the content

– Joe
Nov 24 '18 at 14:15







You should be calling await on the SendAsync call as well as the await response.Content.ReadAsStringAsync(); (which you're not currently doing) to get the content

– Joe
Nov 24 '18 at 14:15















Got it works fine. Thank you all !! :)

– dmxyler
Nov 24 '18 at 14:28





Got it works fine. Thank you all !! :)

– dmxyler
Nov 24 '18 at 14:28












1 Answer
1






active

oldest

votes


















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;


}
}
}





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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;


    }
    }
    }





    share|improve this answer




























      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;


      }
      }
      }





      share|improve this answer


























        0












        0








        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;


        }
        }
        }





        share|improve this answer













        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;


        }
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 14:39









        dmxylerdmxyler

        127




        127

















            Popular posts from this blog

            Ottavio Pratesi

            Tricia Helfer

            15 giugno