Javascript 中的decodeURI和 asp.net HttpUtility.UrlEncode之间的乱码解决方案
来源:互联网 发布:淘宝店营业执照 编辑:程序博客网 时间:2024/06/05 18:27
client端不动:
server:
public class HttpTools
{
public HttpTools()
{
//
// TODO: Add constructor logic here
//
}
public static string EzUrlEncode(string str)
{
if (string.IsNullOrEmpty(str))
return string.Empty;
byte[] bytes = Encoding.UTF8.GetBytes(str);
byte[] data = UrlEncodeBytesToBytesInternal(bytes, 0, bytes.Length, false);
return Encoding.ASCII.GetString(data);
}
internal static bool IsSafe(char ch)
{
if ((((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'))) || ((ch >= '0') && (ch <= '9')))
{
return true;
}
switch (ch)
{
case '!':
case '@':
case '$':
case '&':
case '*':
case '(':
case ')':
case '=':
case ':':
case '/':
case ';':
case '?':
case '+':
case '/'':
case ',':
return true;
}
return false;
}
internal static char IntToHex(int n)
{
if (n <= 9)
{
return (char)(n + 0x30);
}
return (char)((n - 10) + 0x61);
}
private static byte[] UrlEncodeBytesToBytesInternal(byte[] bytes, int offset, int count, bool alwaysCreateReturnValue)
{
int num = 0;
int num2 = 0;
for (int i = 0; i < count; i++)
{
char ch = (char)bytes[offset + i];
if (ch == ' ')
{
num++;
}
else if (!IsSafe(ch))
{
num2++;
}
}
if ((!alwaysCreateReturnValue && (num == 0)) && (num2 == 0))
{
return bytes;
}
byte[] buffer = new byte[count + (num2 * 2)];
int num4 = 0;
for (int j = 0; j < count; j++)
{
byte num6 = bytes[offset + j];
char ch2 = (char)num6;
if (IsSafe(ch2))
{
buffer[num4++] = num6;
}
else if (ch2 == ' ')
{
buffer[num4++] = 0x20;
}
else
{
buffer[num4++] = 0x25;
buffer[num4++] = (byte)IntToHex((num6 >> 4) & 15);
buffer[num4++] = (byte)IntToHex(num6 & 15);
}
}
return buffer;
}
}
----------------------------------
encodeURI() 方法:把URI字符串采用UTF-8编码格式转化成escape格式的字符串。不会被此方法编码的字符:! @ # $& * ( ) = : / ; ? + '
英文解释:MSDN JScript Reference: The encodeURI method returns an encoded URI. If you pass the result to decodeURI, the original string is returned. The encodeURI method does not encode the following characters: ":", "/", ";", and "?". Use encodeURIComponent to encode these characters. Edge Core Javascript Guide: Encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF- 8 encoding of the character
----------------------------------------------------------------
- Javascript 中的decodeURI和 asp.net HttpUtility.UrlEncode之间的乱码解决方案
- HttpUtility.UrlEncode和Server.UrlEncode 的区别
- javascript中文编码/解析与C#ASP.NET中文编码/解析 C#: Server.UrlEncode() HttpUtility.UrlEncode() javascript: escape() encodeURI() encodeURICom
- 关于 HttpUtility.UrlEncode 和 HttpUtility.HtmlEncode 的区别
- javascript如何调用C#后代码中的过程 和ASP.NET调用JS乱码解决方案
- javascript如何调用C#后代码中的过程 和ASP.NET调用JS乱码解决方案
- javascript如何调用C#后代码中的过程 和ASP.NET调用JS乱码解决方案
- javascript如何调用C#后代码中的过程 和ASP.NET调用JS乱码解决方案
- javascript如何调用C#后代码中的过程 和ASP.NET调用JS乱码解决方案
- [转]ASP.net中的Server.UrlEncode函数和ASP中的Server.URLEncode函数返回的值竟然不一样!!!!
- ASP.net中的Server.UrlEncode函数和ASP中的Server.URLEncode函数返回的值竟然不一样!!!!
- ASP.net中的Server.UrlEncode函数和ASP中的Server.URLEncode函数返回的值竟然不一样!!!!
- HttpUtility.UrlEncode() 和Server.UrlEncode()区别
- 解决Server.UrlEncode和客户端的decodeURI问题
- HttpUtility.UrlEncode,Server.UrlEncode 的区别
- C#里HttpUtility.UrlEncode和JS端转换的心得
- c#asp.net url 传递中文参数要使用 System.Web.HttpUtility.UrlEncode 而不能使用Server.UrlEncode
- c#asp.net url 传递中文参数要使用 System.Web.HttpUtility.UrlEncode 而不能使用Server.UrlEncode
- uiuy
- sizeof()的讨论
- ACE命令行参数解析及配置文件读取
- DATASTORE应用
- 属性驱动设计
- Javascript 中的decodeURI和 asp.net HttpUtility.UrlEncode之间的乱码解决方案
- fgchgfujhy
- 初始化类中的静态数组
- 这一刻,我不是我。
- 利用Rational Rose进行C++代码的逆向工程介绍
- 重写自己的hashCode()方法
- SQL Server2000数据库连接池配置
- IdFTP下载文件时的时间比较
- win command