2

I have a problem with encoding, I want to set encoding for example to HttpWebResponse resp, everywhere where I look it says something like that resp.ContentEncoding = Encoding.UTF8, but in practice that is wrong, because it says that ContentEncoding is a read-only property, please help me.

Brian Dishaw
  • 5,767
  • 34
  • 49
Vahan
  • 3,016
  • 3
  • 27
  • 43

1 Answers1

6

You need to differentiate between two similar-sounding but very different classes:

  • HttpWebReponse is the response received in code from a web request. In other words, you don't get to set the data on it, because it was sent by another server.

  • HttpResponse is the response your code is sending from ASP.NET. This is the object you get to write your response data to... and the ContentEncoding property is writable.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194