Click to See Complete Forum and Search --> : Change Encoding


Akademos
June 12th, 2003, 06:15 AM
Hi,
I'm getting a UTF-8 encoded stream via POST Data. I read the stream out into a String Variable. When I pass this variable to a XML document it throws me an error. When I save the String variable to a file i've got following:
<s e l e c t e d > b l a b l a b l a < / s e l e c t e d >
It seems that this is the problem why my XML can't be loaded.
I try following code to convert the POST Data to a correct string:

private void Page_Load(object sender, System.EventArgs e)
{

System.Text.Encoding ascii = System.Text.Encoding.ASCII;
System.Text.Encoding contentEncode = Context.Request.ContentEncoding;


byte[] arrByte = Context.Request.BinaryRead( Context.Request.ContentLength );
byte[] arrAscii = System.Text.Encoding.Convert( contentEncode,ascii,arrByte );
char[] asciiChars = new char[ascii.GetCharCount(arrAscii, 0, arrAscii.Length)];

ascii.GetChars(arrAscii, 0, arrAscii.Length, asciiChars, 0);
String sPostData = new String(asciiChars);
}


But this isn't working also. Does anyone knows how to solve this problem?

Thanks In Advance

Akademos

pareshgh
June 16th, 2003, 07:23 PM
i can see some problem with your statement
byte[] arrAscii = System.Text.Encoding.Convert( contentEncode,ascii,arrByte );


so then
System.Text.Encoding ascii = System.Text.Encoding.ASCII;
System.Text.Encoding contentEncode = Context.Request.ContentEncoding;

how does these matter ??
well you need to get from ContentEncoding !
why ascii though !!





Paresh