关于“推荐”标题

时间:2016-01-25 06:53:45

标签: node.js http erlang sip

我有一个Refer-To标题:

Refer-To: <additional.session.xfer@sccas.home1.net?Target-Dialog=ksdjfhwrklf%3Bremote-tag=676723565%3Blocal-tag=45418454&Require=tdialog&From=tel:+1-237-555-1111&To=tel:+1-987-654-3210&Content-Type=application%2Fsdp&body=v%3D0%0D%0Ao%3D-%202987933623%202987933623%20IN%20IP6%205555::ggg:fff:aaa:bbb%0D%0As%3D-%0D%0Ac%3DIN%20IP6%205555::ggg:fff:aaa:bbb%0D%0At%3D0%200%0D%0Aaudio%203456%20RTP%2FAVP%2097%2096%0D%0Ab%3DAS:25.4%0D%0Aa%3Drtpmap:97%20AMR%0D%0Aa%3Dfmtp:97%20mode-set%3D0%2C2%2C5%2C7%3B%20mode-change-period%3D2%0D%0Aa%3Dmaxptime:20%0D%0A>

在此标题中,有很多%3B%0D等等。

我想知道如何将它们转换为人类可读的?

2 个答案:

答案 0 :(得分:2)

这称为URL编码。您要查找的内容在Erlang中为http_uri:decode/1,在Javascript中为decodeURIComponent

答案 1 :(得分:-2)

这是一个转换所有%XX的C方法:

%XX的每个出现都代表一个字符的十六进制值 以ascii格式。例如,&#34;%3D&#34;是&#34; =&#34;

void
__osip_uri_unescape (char *string)
{
  size_t alloc = strlen (string) + 1;
  unsigned char in;
  int index = 0;
  unsigned int hex;
  char *ptr;

  ptr = string;
  while (--alloc > 0) {
    in = *ptr;
    if ('%' == in) {
      /* encoded part */
      if (alloc > 2 && sscanf (ptr + 1, "%02X", &hex) == 1) {
        in = (unsigned char) hex;
        if (*(ptr + 2) && ((*(ptr + 2) >= '0' && *(ptr + 2) <= '9') || (*(ptr + 2) >= 'a' && *(ptr + 2) <= 'f') || (*(ptr + 2) >= 'A' && *(ptr + 2) <= 'F'))) {
          alloc -= 2;
          ptr += 2;
        }
        else {
          alloc -= 1;
          ptr += 1;
        }
      }
      else {
        break;
      }
    }

    string[index++] = in;
    ptr++;
  }
  string[index] = 0;            /* terminate it */
}