为什么需要对URL进行编码和解码? [英] Why need encode and decode urls?

查看:269
本文介绍了为什么需要对URL进行编码和解码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读问题为什么需要对URL进行编码

但我仍然感到困惑:

  • 为什么W3C只允许URL中包含更多字符?这样可以避免编码?
  • 为什么存在解码

推荐答案

字符的URL表示可能与代码中的字符不同.换句话说,有一个特定的语法定义了URL的组装方式.构成网址所使用的特殊字符需要进行编码,以免导致意外结果.

The URL representation of characters may differ from the characters you have in your code. In other words, there is a specific grammar that defines how URLs are assembled. Special characters that are used in forming a URL need to be encoded so that they do not cause unexpected results.

现在更具体地回答您的问题:

Now to answer your questions more specifically:

  1. 它们可能已经允许您考虑使用某些字符,但是这些字符(例如&,?)具有特殊含义,可以以某种方式起作用.因此,不能在不同的上下文中使用它们.在您发布的问题的链接上,它也看起来像是空格字符的示例,因为它在使用中会带来问题,因此不被支持.

  1. They may already allow some of the characters you are thinking of, but these characters (&, ?, for example) are given special meaning to function in a certain way. Therefore, they cannot be used in a different context. From the link to the question you posted, it also looks like in the example of the space character, it is not supported because of the problems it would introduce in its use.

在将URL编码为应用程序中的操作/其他功能之前,解码可用于解码URL以获取URL的字符串表示形式.

Decode is useful for decoding the URL to get the string representation of the URL before it was encoded for manipulation/other functions in the application.

这篇关于为什么需要对URL进行编码和解码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆