Administrator
发布于 2025-01-15 / 5 阅读
0
0

Content-Type & Circumstance

form-urlencoded & Query Parameters

当我们在HTTP中使用 MIME 类型为x-www-form-urlencoded格式提交数据时,所使用的就是前文所介绍的编码方式。

默认情况下,Content-Type: application/x-www-form-urlencoded。

也就是说,如果我们不指定Content-Type,默认情况下,都是x-www-form-urlencoded,适用于Get和Post请求。

如果Content-Type为application/x-www-form-urlencoded ,且是 GET 请求,那么数据会拼接在 Query 中,也就是我们常说的Query Parameters;

如:field1=value1&field2=value2&field3=value3

包含了如下标准:

  1. Query string 由一组键值对(feild-value)组成;
  2. 每组键值对的 feildvalue=分割;
  3. 每组数据用&分割;

如果Content-Type为application/x-www-form-urlencoded ,且是 POST 请求,则会将数据放置在消息体(body)中,通过Header中的Content-Type 来指定 MIME 类型。

如:

image-20250115092853756

URI & URL & URN

URI 属于父类,而 URL 属于 子类。也就是说,URL是URI众多类型的中的一种。

URI = URL + URN

image-20250115095938511

接下来,我们再来分别讨论这3个术语,他们的概念和作用

The URI acronym stands for Uniform Resource Identifier

The URL is an acronym that stands for Uniform Resource Locator.

Both URLs and URIs follow the same specification: RFC 3986.

URL: allow you to locate a resource, is intended as an address to get a resource.

URI: simply identifies a resource,just as an identifier for resource,类似于数据库中的唯一id

Going back to the address example, if you say you live in the only yellow house in your town, you are not giving directions on how to get there. However, this information identifies your house among the others in your town.

URN stands for Uniform Resource Name, and its scope is to identify resources in a permanent way, even after that resource does not exist anymore.

In particular, a URN is a URI whose scheme is urn and has the following structure, as described by the RFC 2141:

urn:<NAMESPACE-IDENTIFIER>:<NAMESPACE-SPECIFIC-STRING>

The <NAMESPACE-IDENTIFIER> placeholder stands for a string representing the resource category you want to identify.

The <NAMESPACE-SPECIFIC-STRING> is the resource's specific identifier, and its format depends on the namespace identifier.

The following are examples of URNs:

urn:isbn:1234567890
urn:ISSN:0167-6423
urn:ietf:rfc:2648

Those URNs identify objects of different types.

For example, urn:isbn:1234567890 identifies a publication through the ISBN system;

urn:ISSN:0167-6423 identifies a publication through the ISSN system;

urn:ietf:rfc:2648 is an RFC issued by the IETF.

image-20250115100827157

在Java中的转换

java.net.URL
    
java.net.URI
    
convert between these two classes using URL.toURI() and URI.toURL().

评论