sajad
sajad

Reputation: 931

I am not able to get the response content from API call

I am doing a post request and reading the response as given

var response = client.PostAsync(uriBuilder.Uri.ToString(), Content).Result;
var value = response.Content.ReadAsStreamAsync().Result; 

if the result is a proper json string, it populates that in 'value' variable otherwise it returns empty.

but if run the same in postman or fiddler i get this as response

enter image description here

Is there a way to get this response too?

Upvotes: 1

Views: 850

Answers (1)

maxbeaudoin
maxbeaudoin

Reputation: 6966

ReadAsStreamAsync() returns a Task<System.IO.Stream> and not a Task<string>. The json string that you see is probably the debugger showing you the content of the stream.

Consider using ReadAsStringAsync() to get the HTML content :

var response = await client.PostAsync(uriBuilder.Uri.ToString(), Content);
var result = await response.Content.ReadAsStringAsync(); 

Upvotes: 1

Related Questions