-
URL Encode
用VC实现post数据常常会遇到URL编码问题
在此封装一个工具类进行UTF8编码的转换
源码来自php source code
只是简单的封装给C++调用
- //URL 编解码类
- //来自PHP源码
- class CRtUrlConv
- {
- public:
- static char *urlencode(const char *in_str )
- {
- char *out_str;
- int in_str_len, out_str_len;
- in_str_len=strlen(in_str);
- out_str_len=0;
- out_str = php_url_encode( in_str , in_str_len, &out_str_len);
- return (char *) out_str;
- }
- static int urldecode(char *s)
- {
- return php_url_decode(s);
- }
- private:
- static char *php_url_encode(const char *s , int len , int *new_length)
- {
- register unsigned char c;
- unsigned char *to, *start;
- unsigned char const *from, *end;
- from = (unsigned char *)s;
- end = (unsigned char *)s + len;
- start = to = new unsigned char[3*len+1];
- while (from < end) {
- c = *from++;
- if (c == ' ') {
- *to++ = '+';
- #ifndef CHARSET_EBCDIC
- } else if ((c < '0' && c != '-' && c != '.') ||
- (c < 'A' && c > '9') ||
- (c > 'Z' && c < 'a' && c != '_') ||
- (c > 'z')) {
- to[0] = '%';
- to[1] = HEXCHARS[c >> 4];
- to[2] = HEXCHARS[c & 15];
- to += 3;
- #else /*CHARSET_EBCDIC*/
- } else if (!isalnum(c) && strchr("_-.", c) == NULL) {
- /* Allow only alphanumeric chars and '_', '-', '.'; escape the rest */
- to[0] = '%';
- to[1] = HEXCHARS[os_toascii[c] >> 4];
- to[2] = HEXCHARS[os_toascii[c] & 15];
- to += 3;
- #endif /*CHARSET_EBCDIC*/
- } else {
- *to++ = c;
- }
- }
- *to = 0;
- if (new_length) {
- *new_length = to - start;
- }
- return (char *) start;
- }
- static int php_url_decode(char *str)
- {
- int len;
- char *dest = str;
- char *data = str;
- len=strlen(str);
- while (len--) {
- if (*data == '+') {
- *dest = ' ';
- }
- else if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1))
- && isxdigit((int) *(data + 2))) {
- #ifndef CHARSET_EBCDIC
- *dest = (char) php_htoi(data + 1);
- #else
- *dest = os_toebcdic[(char) php_htoi(data + 1)];
- #endif
- data += 2;
- len -= 2;
- } else {
- *dest = *data;
- }
- data++;
- dest++;
- }
- *dest = '/0';
- return dest - str;
- }
- static int php_htoi(char *s)
- {
- int value;
- int c;
- c = ((unsigned char *)s)[0];
- if (isupper(c))
- c = tolower(c);
- value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16;
- c = ((unsigned char *)s)[1];
- if (isupper(c))
- c = tolower(c);
- value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10;
- return (value);
- }
- static const char hexchars[];
- static const char HEXCHARS[];
- };
- const char CRtUrlConv::hexchars[] = "0123456789abcdef";
- const char CRtUrlConv::HEXCHARS[] = "0123456789ABCDEF";
- }
最新更新
URL Encode
python爬虫学习
python爬虫学习——列表
go语言写http踩得坑
【Python】爬虫笔记-从PyMySQL到DBUtils
【Python】爬虫笔记-开源代理池haipproxy使用
Python规范:提高可读性
C语言两结构体之间的成员互换
【爬虫实战项目】Python爬取Top100电影榜单
linux(Ubuntu)安装python
SqlServer服务中利用触发器对指定账户进行
一次SQL调优 聊一聊 SQLSERVER 数据页
聊一聊 SQLSERVER 的行不能跨页
再聊一下那 SQLSERVER 行不能跨页的事
大数据概述
支线第九篇:
数据库的值获取过来转换成Json数组的方法
支线第八篇:数据类型转换
支线第七篇:又是解决报错
支线第六篇:停下脚步,理清思路
浅谈JS词法环境
js对象的理解
原型和原型链的深入浅出
JavaScript实现数组对象去重
关于 NodeJs 处理超长字符串问题的分析
JavaScript中的函数
使用JS的DOM(文档对象模型)获取前端循
JS web sql database 几个功能组合的实现
30个Javascript知识点总结,总有你不会的!
【促进开发】上海道宁与DHTMLX为您提供易