利用C语言进行urldecode,解决浏览器中的urlencode
来源:互联网 发布:各层网络协议 编辑:程序博客网 时间:2024/05/17 01:22
利用C语言进行urldecode,解决浏览器中的urlencode
#include <stdio.h>#include <stdlib.h>#include <string.h>int isDigit(unsigned char ch){if(ch>= '0' && ch <= '9'){return 1;}else{return 0;}}unsigned char character_to_hex(unsigned char highByte, unsigned char lowByte){highByte = isDigit(highByte)? (highByte - '0'):(highByte - 'A' + 10);lowByte = isDigit(lowByte)? (lowByte - '0'):(lowByte - 'A' + 10);return ((highByte<<4) + lowByte);}unsigned char* urldecode(unsigned char* srcBuf, int srcLen, int *outLen){if(NULL == srcBuf || srcLen<= 0){return NULL;}unsigned char* dstBuf = NULL;dstBuf = (unsigned char *)malloc(srcLen);if(NULL == dstBuf){return NULL;}int i=0, j=0;for(i=0; i<srcLen; i++){if(srcBuf[i] == '%'){dstBuf[j] = character_to_hex(srcBuf[i+1], srcBuf[i+2]);i+=2;}else if(srcBuf[i] == '+'){dstBuf[j] = ' ';}else{dstBuf[j] = srcBuf[i];}j++;}*outLen = j;return dstBuf;}int main(int argc, char *argv[]){if(argc != 2){printf("few paramter...\n");printf("Usage: ./urldecode szURL\n");return -1;}int size = 0;unsigned char* dst = urldecode(argv[1], strlen(argv[1]), &size);printf("%s\n", dst);return 0;}
0 0
- 利用C语言进行urldecode,解决浏览器中的urlencode
- URLDecode 和 URLEncode 在 C 中的实现
- URLDecode 和 URLEncode 在 C 中的实现中的 URLEncode
- Qt进行urlEncode/urlDecode
- python中的urlencode与urldecode
- python中的urlencode与urldecode
- python中的urlencode与urldecode
- python中的urlencode与urldecode
- python中的urlencode和urldecode
- python中的urlencode与urldecode
- python中的urlencode与urldecode
- python中的urlencode和urldecode
- python中的urlencode与urldecode
- python中的urlencode与urldecode
- python中的urlencode与urldecode
- python中的urlencode与urldecode
- python中的urlencode与urldecode
- python中的urlencode与urldecode
- Mac下git的安装与配置
- 软件测试学习随记
- Cglib 与 JDK动态代理的运行性能比较
- 24个设计模式学习
- Cocos2d-x中Vector容器以及实例介绍
- 利用C语言进行urldecode,解决浏览器中的urlencode
- git的使用介绍
- hdu 5000 dp+猜
- 虚拟机通过host-only上网
- Codeforces Round 313 找规律
- Android MediaExtractor setDataSource
- Just a Numble HDU杭电2117
- C++中数组a与&a,&a[0]
- 安卓和苹果的安全性及生态环境对比