#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**** num <---> char ****/
#define HEX2C(x) (((x)>9)?(('a'-10)+(x)):('0'+(x)))
#define C2HEX(x) (unsigned char)( (x)>'a'? (x-'a'+10):(x-'0') )
/**** 16进制 <---> 10进制 ****/
#define HEX_TO_DECIMAL(char1, char2) \
(((char1 >= 'A') ? (((char1 & 0xdf) - 'A') + 10) : (char1 - '0')) * 16) + \
(((char2 >= 'A') ? (((char2 & 0xdf) - 'A') + 10) : (char2 - '0')))
int hexa(char c)
{
switch (c) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
case 'A':
case 'a': return 10;
case 'B':
case 'b': return 11;
case 'C':
case 'c': return 12;
case 'D':
case 'd': return 13;
case 'E':
case 'e': return 14;
case 'F':
case 'f': return 15;
}
return 0;
}
char *makespace (char *s)
{
int i,len;
len=strlen(s);
for(i=0;i<len;i++) {
if(s[i]=='+')
s[i]=' ';
}
return s;
}
char *convert(char *s)
{
int x,y,len;
char *data;
len=strlen(s);
data=(char*)malloc(sizeof(char)*(len+1));
strcpy(data,s);
y=0;
for(x=0;x<len;) {
if(s[x]!='%') {
data[y]=data[x];
y++;
x++;
}
else {
data[y]=(char)(16*hexa(s[x+1])+hexa(s[x+2]));
y++;
x=x+3;
}//endif
}//endfor
data[y]='\0';
return data;
}
int main(void)
{
char *tmp;
char code[256]="val=%7B%22ip%22%3A%22192.168.10.55%22%7D";
tmp=makespace(code);
tmp=convert(tmp);
printf("%s\n",tmp);
return 0;
}
URL post数据解码
最新推荐文章于 2023-07-25 00:07:47 发布