What's the correct encoding of HTTP get request strings?

后端 未结 3 1053
余生分开走
余生分开走 2020-11-29 09:54

Does the HTTP standard or something define which encoding should be used on special characters before they are encoded in url with %XXs? If it doesn\'t define is there a way

3条回答
  •  难免孤独
    2020-11-29 10:40

    As far as I'm aware, there is no way to define it, though I've always assumed that it is ASCII, since that is what DNS is (currently, though localised DNS is coming, with all the problems that entails).

    Note: UTF8 is "ASCII compatible" unless you try to use extended characters. This probably plays some small part in the reasoning behind why some browsers might send their GET data UTF8 encoded.

    EDIT: From your comment, it seems like you don't know how the % encoding works at all, so here goes.

    Given the following string query string, "?foo=Hello World!", the "Hello World!" part needs URL encoding. The way this works is any 'special' characters get their ASCII value taken and converted to hex prefixed by a '%'. So the above string would convert to "?foo=Hello%20World%21".

提交回复
热议问题