C++实现urlencode,urldecode
来源:互联网 发布:有淘宝秒杀软件吗 编辑:程序博客网 时间:2024/05/21 04:21
namespace HttpUtility{ typedef unsigned char BYTE; inline BYTE toHex(const BYTE &x) { return x > 9 ? x -10 + 'A': x + '0'; } inline BYTE fromHex(const BYTE &x) { return isdigit(x) ? x-'0' : x-'A'+10; } inline string URLEncode(const string &sIn) { string sOut; for( size_t 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] ) ) //貌似把空格编码成%20或者+都可以 //{ // buf[0] = '+'; //} else { buf[0] = '%'; buf[1] = toHex( (BYTE)sIn[ix] >> 4 ); buf[2] = toHex( (BYTE)sIn[ix] % 16); } sOut += (char *)buf; } return sOut; }; inline string URLDecode(const string &sIn) { string sOut; for( size_t ix = 0; ix < sIn.size(); ix++ ) { BYTE ch = 0; if(sIn[ix]=='%') { ch = (fromHex(sIn[ix+1])<<4); ch |= fromHex(sIn[ix+2]); ix += 2; } else if(sIn[ix] == '+') { ch = ' '; } else { ch = sIn[ix]; } sOut += (char)ch; } return sOut; }}
感谢:http://www.cnitblog.com/luckydmz/archive/2010/10/12/69959.html
- URLDecode 和 URLEncode 在 C 中的实现
- 一个urlencode/urldecode的C实现
- URLDecode 和 URLEncode 在 C 中的实现中的 URLEncode
- C++实现urlencode,urldecode
- C++实现UrlEncode和UrlDecode
- C++实现UrlEncode和UrlDecode
- UrlEncode UrlDecode
- urlencode urldecode
- urlencode,urldecode
- JavaScript 实现URLEncode、URLDecode (GB2312版)
- 利用C语言进行urldecode,解决浏览器中的urlencode
- VB中实现ASP中Server.URLEncode与Server.URLDecode
- 在SQL Server 2005中实现 Server.UrlEncode、Server.UrlDecode
- 实现Server.UrlEncode和Server.UrlDecode功能的js代码
- JavaScript实现UrlEncode,UrlDecode(兼容FF,IE等)
- 用JavaScript和vbscript实现UrlEncode和UrlDecode
- 用JavaScript实现UrlEncode和UrlDecode的脚本代码
- 网络传输文本,urlEncode和urldecode的iOS实现。
- 【2012百度之星资格赛】J:百度的新大厦
- 第十五周实验报告2
- GESE考试中级段 7---9级
- IGMP技术总结(2)
- C++面试基础知识
- C++实现urlencode,urldecode
- create socket by pthread
- 登录作业
- UIView的 frame 的origin 还是左上角,而不是想的中央
- 无题
- .net 简单实现加密
- InvokeRequired 属性与Invoke方法
- Hibernate 是如何管理数据库表的关联关系的
- inner/outer join in hibernate