VC环境实现UrlDecode示例
/*
URLEncode是这样编码的
1。数字和字母不变。
2。空格变为"+"号。
3。其他被编码成"%"加上他们的ascii的十六进制,规律是这样的
比如“啊”字 Ascii的十六进制是B0A1——%B0%A1(Note:它是每个字节前加个%)。
*/
#include iostream
#include string
#include fstream
#include ctype.h
#include stdlib.h
using namespace std;
typedef unsigned char BYTE;
inline BYTE toHex(const BYTE x)
{
return x 9 ? x + 55: x + 48;
}
string urlEncoding( string sIn )
{
cout "size: " sIn.size() endl;
string sOut;
for( int ix = 0; ix sIn.size(); ix++ )
{
BYTE buf[4];
memset( buf, 0, 4 );
if( isalnum( (BYTE)sIn[ix] ) )
{
buf[0] = sIn[ix];
}
else if ( isspace( (BYTE)sIn[ix] ) )
{
buf[0] = '+';
}
else
{
buf[0] = '%';
buf[1] = toHex( (BYTE)sIn[ix] 4 );
buf[2] = toHex( (BYTE)sIn[ix] % 16);
}
sOut += (char *)buf;
}
return sOut;
}
int main(int argc, char *argv[])
{
string src;
ifstream inFile( "in.txt" );
if( !inFile )
{
cout "not in.txt to read" endl;
system("PAUSE");
return -1;
}
inFile src;
string sOut = urlEncoding( src );
cout sOut endl;
system("PAUSE");
return 0;
}
PHP urldecode示例
$str1=urlencode("百度"); //$str1的值是%B0%D9%B6%C8
$str2=urldecode($str1); //$str2的值就是“百度”
urlencode()函数原理就是首先把中文字符转换为十六进制,然后在每个字符前面加一个标识符%。 urldecode()函数与urlencode()函数原理相反,用于解码已编码的 URL 字符串,其原理就是把十六进制字符串转换为中文字符
urldecode是地址栏编码方式,就是用百分号加上每个字符的十六进制值。解码很简单,可以使用javascript的unescape()来解码。如:
alert(unescape("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70")); //解码成明文再弹出来显示。
在你提问的PHP代码中也可以直接在后面加一句输出显示的代码即可看到解码后的内容:
echo $O00OO0;
要再前台也中想办法,我的解决方案是不用A标记,用js脚本,onclick=window.open()然后用escape()方法URL编码这样传递后 在后台代码中使用Server.UrlDecode()方法 对url进行解码
.aspx?gid=fb68e168-ae3e-4f36-933f-6f03d8723d9ctempid=-1 gid 参数名 后面的值是一个uuid 具体代表什么不清楚 tempid 第二个参数 值为-1
测试中提交的中文参数 需要进行URL转码
使用函数 ${__urlencode()}
例如 :
${__urlencode(你好)}
${__urlencode(${参数变量})}
测试中返回的中文参数 需要进行URL 解码
使用函数 ${__urldecode()}
例如 :
${__urldecode(%E4%BB%93%E5%BA%93)}
${__urldecode(${参数变量})}
原文地址