编码格式问题 怎么把一个汉字转换为URLEncode格式,而不是用URLEncode() 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用javascript的enscape方法或者自己写个加密算法 winform里面URLEncode不能用吧?你可以在javascript里用encodeURLComponent或者enscape winform里面可以用URLEncode!添加引用即可!另反编译HttpServerUtility.UrlEncode后面是逐层调用的方法public string UrlEncode(string s){ Encoding encoding1 = (this._context != null) ? this._context.Response.ContentEncoding : Encoding.UTF8; return HttpUtility.UrlEncode(s, encoding1);}public static string UrlEncode(string str, Encoding e){ if (str == null) { return null; } return Encoding.ASCII.GetString(HttpUtility.UrlEncodeToBytes(str, e));}public static byte[] UrlEncodeToBytes(string str, Encoding e){ if (str == null) { return null; } byte[] buffer1 = e.GetBytes(str); return HttpUtility.UrlEncodeBytesToBytesInternal(buffer1, 0, buffer1.Length, false);}private static byte[] UrlEncodeBytesToBytesInternal(byte[] bytes, int offset, int count, bool alwaysCreateReturnValue){ int num1 = 0; int num2 = 0; for (int num3 = 0; num3 < count; num3++) { char ch1 = (char) bytes[offset + num3]; if (ch1 == ' ') { num1++; } else if (!HttpUtility.IsSafe(ch1)) { num2++; } } if ((!alwaysCreateReturnValue && (num1 == 0)) && (num2 == 0)) { return bytes; } byte[] buffer1 = new byte[count + (num2 * 2)]; int num4 = 0; for (int num5 = 0; num5 < count; num5++) { byte num6 = bytes[offset + num5]; char ch2 = (char) num6; if (HttpUtility.IsSafe(ch2)) { buffer1[num4++] = num6; } else if (ch2 == ' ') { buffer1[num4++] = 0x2b; } else { buffer1[num4++] = 0x25; buffer1[num4++] = (byte) HttpUtility.IntToHex((num6 >> 4) & 15); buffer1[num4++] = (byte) HttpUtility.IntToHex(num6 & 15); } } return buffer1;} 呃...LZ说JS也不能用...那咋整... 那就自己写个UrlEncode了 还不是一样 to viena(维也纳nn):谢谢 知道能用,感觉很别扭,CS上用到HttpServerUtility我想问,能不能可以通过编码格式来产生,ENCODING类 我反编译HttpServerUtility.UrlEncode的源码就是给你参考它的实现方法的呀 System.Web.HttpUtility.UrlEncode 怎样让hyperlink的文本,鼠标移到上面时变色 GridView嵌套控件问题 急 请教,如何快速打开对象的定义文件 ASP.net/C#大家刚入门的时候是从哪本教材学起的啊? 生成xml 一个图片上传的问题,希望大家抽空帮忙看一看`` 对象引用未初始化问题 很简单的问题 请问各位老大,目前有哪些.net 3.5 的开源基础框架比较好用? 大家给推荐几种易用(对用户而言)、易实现(对我)、美观的TreeView增删改方式(求思路) 超级无敌 菜鸟问题 如何获取MSSQL存储过程中返回的多个结果集?
你可以在javascript里用encodeURLComponent或者enscape
添加引用即可!
另
反编译HttpServerUtility.UrlEncode
后面是逐层调用的方法public string UrlEncode(string s)
{
Encoding encoding1 = (this._context != null) ? this._context.Response.ContentEncoding : Encoding.UTF8;
return HttpUtility.UrlEncode(s, encoding1);
}public static string UrlEncode(string str, Encoding e)
{
if (str == null)
{
return null;
}
return Encoding.ASCII.GetString(HttpUtility.UrlEncodeToBytes(str, e));
}
public static byte[] UrlEncodeToBytes(string str, Encoding e)
{
if (str == null)
{
return null;
}
byte[] buffer1 = e.GetBytes(str);
return HttpUtility.UrlEncodeBytesToBytesInternal(buffer1, 0, buffer1.Length, false);
}
private static byte[] UrlEncodeBytesToBytesInternal(byte[] bytes, int offset, int count, bool alwaysCreateReturnValue)
{
int num1 = 0;
int num2 = 0;
for (int num3 = 0; num3 < count; num3++)
{
char ch1 = (char) bytes[offset + num3];
if (ch1 == ' ')
{
num1++;
}
else if (!HttpUtility.IsSafe(ch1))
{
num2++;
}
}
if ((!alwaysCreateReturnValue && (num1 == 0)) && (num2 == 0))
{
return bytes;
}
byte[] buffer1 = new byte[count + (num2 * 2)];
int num4 = 0;
for (int num5 = 0; num5 < count; num5++)
{
byte num6 = bytes[offset + num5];
char ch2 = (char) num6;
if (HttpUtility.IsSafe(ch2))
{
buffer1[num4++] = num6;
}
else if (ch2 == ' ')
{
buffer1[num4++] = 0x2b;
}
else
{
buffer1[num4++] = 0x25;
buffer1[num4++] = (byte) HttpUtility.IntToHex((num6 >> 4) & 15);
buffer1[num4++] = (byte) HttpUtility.IntToHex(num6 & 15);
}
}
return buffer1;
}
那咋整...
我想问,能不能可以通过编码格式来产生,ENCODING类