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,649
  • 33
  • 49
Vahan
  • 1,847
  • 2
  • 21
  • 40

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,335,956
  • 823
  • 8,931
  • 9,049