Hi~!
Thanks in advance for those who will be looking into my problem.
I am having difficulty in sending chinese characters via postmethod.
// Create an instance of HttpClient
HttpClient httpclient = new HttpClient();
// Create a method instance
PostMethod postmethod = new PostMethod(url);
// Assign parameters into post method
Iterator it = paramList.keySet().iterator();
while (it.hasNext()) {
String paramName = (String) it.next();
postmethod.addParameter(paramName,
new String(((String) paramList.get(paramName)).getBytes("UTF-8"),"UTF-8"));
}
With the above codes I succeeded in sending out the postmethod with the list of
parameters. But all chinese characters become "?" upon received by back-end.
Therefor I add this:
// Set request header - character set
postmethod.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
With the above lines added, the back-end server could receive the postmethod request
but can only find an empty parameter list.
The back-end server is indeed a servlet resided on websphere 5 server. The codes to
get the one of the parameter is:
request.setCharacterEncoding("UTF-8");
String inXMLMessage = (String) request.getParameter("xmlmessage");
Since the parameter list become empty the above method failed. Therefore I switched
to another method - to get the entire request body with input stream and added the
following codes:
if (inXMLMessage == null)
inXMLMessage = getXMLMessageFromInputStream (request.getInputStream());
......
public String getXMLMessageFromInputStream (InputStream requestIS) {
String XMLMessage = "";
try {
InputStreamReader isr = new InputStreamReader(requestIS, "UTF-8");
BufferedReader r = new BufferedReader(isr);
XMLMessage = r.readLine();
XMLMessage = URLDecoder.decode(XMLMessage);
XMLMessage = XMLMessage.substring(11);
} catch (Exception ex) {...}
return XMLMessage;
}
With the above I succeeded to get the parameter I want, i.e. an xml message, from the
input stream, but the entire message are "escaped", that is space and tab become "+",
"<" become "%3C", etc. Thaz why I need to use URLDecoder . But the worst part is
that all chinese charaters become weird codes like
測試, which should be "測試" in traditional
chinese.
I am really at my wits end as to what is happening here. Would somebody throw a light
upon my proble? A thousand thanks in advance!
Regards
Ramiel Fong
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]