http url转义字符和特殊字符处理

  • Post author:
  • Post category:其他


根据这个博文,有这些转义


http url转义字符,特殊字符 – yutingliuyl – 博客园

空格 – %20

” – %22

# – %23

% – %25

& – %26

( – %28

) – %29

+ – %2B

, – %2C

/ – %2F

: – %3A

; – %3B

< – %3C

= – %3D

> – %3E

?

– %3F

@ – %40

\ – %5C

| – %7C

根据ESP32的例程对转义处理函数如下

void preprocess_string(char* str)

{


char *p, *q;

for (p = q = str; *p != 0; p++)

{


if (*(p) == ‘%’ && *(p + 1) != 0 && *(p + 2) != 0)

{


// quoted hex

uint8_t a;

p++;//直接去掉%,处理第一个数字

if (*p <= ‘9’)

a = *p – ‘0’;

else

a = toupper((unsigned char)*p) – ‘A’ + 10;

a <<= 4;

p++;//第二个数字

if (*p <= ‘9’)

a += *p – ‘0’;

else

a += toupper((unsigned char)*p) – ‘A’ + 10;

*q++ = a;

}

else if (*(p) == ‘+’) {


*q++ = ‘ ‘;//空格

} else {


*q++ = *p;//不变

}

}

*q = ‘\0’;

}



版权声明:本文为weichushun原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。