-2
當我的android應用程序中的用戶名是西里爾文時,出現錯誤。 我使用TomCat服務器和Eclipse。URLEncoder.encode不適用於西里爾文
對於名爲 「Алексей」,服務器端拋給我:
> SEVERE: Servlet.service() for servlet [default] in context with path
> [/AppServer] threw exception java.lang.IllegalArgumentException:
> java.net.URISyntaxException: Illegal character in query at index 37:
> /AppServer/chat?name=???»?µ?????µ??
我的代碼:?
try {
client = new WebSocketClient(URI.create(WsConfig.URL_WEBSOCKET
+ URLEncoder.encode(name, "UTF-8")), new WebSocketClient.Listener() {
@Override
public void onConnect() {
}
/**
* On receiving the message from web socket server
* */
@Override
public void onMessage(String message) {
Log.d(TAG, String.format("Got string message! %s", message));
parseMessage(message);
}
@Override
public void onMessage(byte[] data) {
Log.d(TAG, String.format("Got binary message! %s",
bytesToHex(data)));
// Message will be in JSON format
parseMessage(bytesToHex(data));
}
/**
* Called when the connection is terminated
* */
@Override
public void onDisconnect(int code, String reason) {
String message = String.format(Locale.US,
"Disconnected! Code: %d Reason: %s", code, reason);
showToast(message);
// clear the session id from shared preferences
utils.storeSessionId(null);
}
@Override
public void onError(Exception error) {
Log.e(TAG, "Error! : " + error);
showToast("Error! : " + error);
}
}, null);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
client.connect();
}
由於URLEncoder.encode(name, "UTF-8")
不幫我,同樣的「???»μ? ????μ??」 = \
任何建議如何解決呢?(
是的,它的工作和輸出是我所需要的,但服務器仍然扔給我「???»?μ?????μ??」 也許TomCat有問題,但是在哪裏? = \ – 2014-11-08 08:21:20