Vahan
Vahan

Reputation: 3288

How to set encoding in C#?

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.

Upvotes: 2

Views: 632

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503200

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.

Upvotes: 6

Related Questions