67,513
社区成员
发帖
与我相关
我的任务
分享
/**
* Utf8URL编码
* @param s
*/
public String Utf8URLencode(String text) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < text.length()/2; i++) {
char c = text.charAt(i);
if (c >= 0 && c <= 255) {
result.append(c);
}else {
byte[] b = new byte[0];
try {
b =text.toString().getBytes("UTF-8");
}catch (Exception ex) {
}
for (int j = 0; j < b.length; j++) {
int k = b[j];
if (k < 0) k += 256;
result.append("%" + Integer.toHexString(k).toUpperCase());
}
}
}
return result.toString();
}
//将传过来的参数 转化成以GB2312编码形式如"交警返回是%BD%BB%BE%AF"
public String GBURLencode(String text) {
StringBuffer result = new StringBuffer();
byte[] b = new byte[0];
try {
b = text.getBytes("GB2312");
}
catch (Exception ex) {
}
for (int j = 0; j < b.length; j++) {
int k = b[j];
if (k < 0) k += 256;
result.append("%" + Integer.toHexString(k).toUpperCase());
}
return result.toString();
}