编码格式问题
怎么把一个汉字转换为URLEncode格式,而不是用URLEncode()
------解决方案--------------------用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;
}
------解决方案--------------------同问