Hello! Faced the problem of obtaining information on request. I send cookies to the server, the answer comes 200, but only the headers come to me, how to get the main body? Thank!

public async void GetData(string sessionId, string tokenId, string adress) { var baseAddress = new Uri(Settings.Default.api_url); using (var handler = new HttpClientHandler { UseCookies = true }) using (var client = new HttpClient(handler) { BaseAddress = baseAddress }) { var message = new HttpRequestMessage(HttpMethod.Get, adress); message.Headers.Add("Cookies", "PHPSESSID=" + sessionId + "; CSRF_TOKEN=" + tokenId); var result = await client.SendAsync(message); result.EnsureSuccessStatusCode(); } } 
  • await result.Content.ReadAsStreamAsync tried? - VladD
  • Yes, only headers come, the main body is not (the generated json answer must come in response) - Elizabeth
  • And what exactly comes in the stream? How do you read information from there? Give the code. - VladD
  • This is all the code. it contains the variables PHPSESSID, CSRF_TOKEN and the address from which to receive the information - Elizaveta
  • The fact is that I cannot get the content of the page until I send the cookie, as confirmation of authorization - Elizaveta

1 answer 1

The issue has been resolved var content = await result.Content.ReadAsStringAsync(); Thank!