使用Java调用.net写的WebService传入中文乱码, 请教高手如何解决
如题:
我知道是编码不一致的问题, 但具体应该怎样解决就不知道了?
我已试过以下的方法都是不行:
1. 客户端处理
String content = new String (input.getBytes( "ISO-8859-1"), "utf8");
2. 客户端处理
String content = new String (input.getBytes( "utf8"), "utf8");
3. 客户端处理
String content = new String (input.getBytes( "gb2312"), "utf8");
4. 客户端处理
String content = new String (input.getBytes( "utf8"), "gb2312");
5. 客户端处理
String content = new String (input.getBytes( "gb2312"), "gb2312");
6. 改服务器端web.config
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
7. 客户端处理
用这个函数处理:
public static String Encoding(String text)
{
if (null == text || 0 == text.trim().length())
return "";
StringBuffer sb = new StringBuffer();
char[] chars = text.toCharArray();
for (int i = 0; i < chars.length; i++)
{
if (chars[i] > 127)
{
sb.append("&#x");
sb.append(Integer.toHexString(chars[i]));
sb.append(";");
}
else
{
sb.append(chars[i]);
}
}
return sb.toString();
}
请各位大侠赐教