[Mono-list] HttpWebResponse : Encoding info (Mono better than .Net ???)

Robert Jordan robertj at gmx.net
Mon Nov 13 07:58:03 EST 2006


xiii29 at free.fr wrote:
> Hi,
> 
> My apps make a request on internet with an HttpWebRequest and an
> HttpWebResponse. For some weeks I got trouble with specials char (é, à, ù
> [...]).
> 
> I find a solution :

That's not really a valid solution. CharacterSet could be everything,
including an invalid value, like "".

Mono's Encoding.GetEncoding () seems to map String.Empty
to the default encoding, which happens to be Latin1 on your
system. MS.NET expects a valid encoding name.

You could try something like that:

static Encoding GetEncoding(string name)
{
	if (name == null || name == String.Empty)
		return Encoding.Default;

	try {
		return Encoding.GetEncoding (name);
	} catch {
		return Encoding.Default;
	}
}

This is still not an optimal solution, because the page's
CharacterSet and the real encoding could be different.
That's a HTTP protocol violation, but you have to expect
that.

Robert



More information about the Mono-list mailing list