某公司提供一HTTP接口,有一个服务器url提供,所有数据用GET方法将参数提交到这个URL,现在有一个问题,我用java开发客户端程序,当java文件保存为ANSI时,不能正常发送数据,当java文件保存为utf-8时,就没有问题....发送的参数先转为16进制,再发送出去...
//转为16进制示例方法
public static String to16(String str)
{

String hs = "";

byte[] byStr = str.getBytes();
for(int i=0;i<byStr.length;i++)
{
String temp = "";
temp = (Integer.toHexString(byStr[i]&0xFF));
if(temp.length()==1) temp = "%0"+temp;
else temp = "%"+temp;
hs = hs+temp;


}

return hs.toUpperCase();

}//Get方法提交
public static String getResult(String urlStr) {
URL url = null;
HttpURLConnection connection = null; try {
url = new URL(urlStr);
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("GET");
connection.setUseCaches(false);
connection.connect(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
}

reader.close();
return buffer.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
}
return null;
}比如,我将"你好",在GBK下转为16进制是   "%C4%E3%BA%C3",在utf-8下转就是 %E4%BD%A0%E5%A5%BD
怎么转换一下啊