send big5 xml request to servlet

M

Mullin Yu

i try to send a big5-encoded xml request to a java servlet by two ways

1. vb6 => success
2. c# => all chinese character becomes ??????

my c# coding is as following:

i wonder will it convert my big5 chinese to utf-8 or utf-16 already before
sending. any clue and suggestion:

mlDocument xmlDOM = new XmlDocument();

xmlDOM.Load("ryan_big5.xml");


/*

string strXML = xmlDOM.OuterXml;

MessageBox.Show(strXML);

Console.WriteLine("Request: " + strXML);

Byte[] data = System.Text.Encoding.ASCII.GetBytes(strXML.ToString());

*/

Byte[] data = System.Text.Encoding.ASCII.GetBytes(xmlDOM.OuterXml);

HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://172.18.2.1:7520/XAIApp/xaiserver_b
ig5");


myRequest.Method = "POST";

myRequest.ContentType="text/xml; encoding=big5";

myRequest.ContentLength = data.Length;



myRequest.Credentials = new NetworkCredential("CDX", "cordaptix");

Stream newStream = myRequest.GetRequestStream();

// Send the data.

newStream.Write(data,0,data.Length);

newStream.Close();


// Get Response

WebResponse myResponse = myRequest.GetResponse();

StreamReader sr = new StreamReader(myResponse.GetResponseStream());


string response = sr.ReadToEnd();

MessageBox.Show(response);

Console.WriteLine("Response: " + response);
 
J

Jon Skeet [C# MVP]

Mullin Yu said:
i try to send a big5-encoded xml request to a java servlet by two ways

Byte[] data = System.Text.Encoding.ASCII.GetBytes(xmlDOM.OuterXml);

If you want to send Big5 data, why on earth are you converting your XML
into ASCII? You're basically lying to the server when you then say:
 
M

Mullin Yu

i found the clue:
Byte[] data =
System.Text.Encoding.GetEncoding("BIG5").GetBytes(xmlDOM.OuterXml);

thanks!

mullin

Jon Skeet said:
Mullin Yu said:
i try to send a big5-encoded xml request to a java servlet by two ways

Byte[] data = System.Text.Encoding.ASCII.GetBytes(xmlDOM.OuterXml);

If you want to send Big5 data, why on earth are you converting your XML
into ASCII? You're basically lying to the server when you then say:
myRequest.ContentType="text/xml; encoding=big5";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top