Get json from curl command [duplicate]
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);
}
}

c# curl
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.
add a comment |
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);
}
}

c# curl
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'sContentproperty.
– 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 callingawaiton theSendAsynccall as well as theawait 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
add a comment |
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);
}
}

c# curl
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);
}
}

This question already has an answer here:
reading my json response from a post request i sent
2 answers
c# curl
c# curl
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'sContentproperty.
– 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 callingawaiton theSendAsynccall as well as theawait 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
add a comment |
You have to read the response'sContentproperty.
– 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 callingawaiton theSendAsynccall as well as theawait 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
add a comment |
1 Answer
1
active
oldest
votes
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;
}
}
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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;
}
}
}
add a comment |
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;
}
}
}
add a comment |
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;
}
}
}
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;
}
}
}
answered Nov 24 '18 at 14:39
dmxylerdmxyler
127
127
add a comment |
add a comment |
You have to read the response's
Contentproperty.– 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
awaiton theSendAsynccall as well as theawait 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