幾個常見 Request Content-Type body 會長怎樣

Willy
Aug 18, 2023

--

  1. application/json:通常用於傳輸 JSON 格式的資料。請求主體可能如下所示:
{
"key": "value",
"array": [1, 2, 3],
"nested": {
"nested_key": "nested_value"
}
}

2. application/x-www-form-urlencoded: 這種 Content-Type 通常用於傳遞以 URL 編碼形式編碼的表單數據。主體結構類似於用 key1=value1&key2=value2 格式編碼的數據。

key1=value1&key2=value2

3. multipart/form-data: 這個 Content-Type 通常用於上傳文件或包含二進制數據的複雜表單數據。請求主體的結構是一個多部分的主體,每個部分都包含不同的數據。

Content-Type: multipart/form-data; boundary=---------------------------1234567890
-----------------------------1234567890
Content-Disposition: form-data; name="text"

Some text content
-----------------------------1234567890
Content-Disposition: form-data; name="file"; filename="example.txt"
Content-Type: text/plain

File content here
-----------------------------1234567890--

4. text/plain: 這個 Content-Type 通常用於傳輸純文本數據。主體結構就是文本內容本身。

This is a plain text body.

5. application/xml: 這個 Content-Type 用於傳輸 XML 格式的數據。XML(eXtensible Markup Language)是一種標記語言,用於結構化數據。

<root>
<element>Value</element>
</root>

--

--

Willy
Willy

Written by Willy

前端修練筆記本,記錄一些踩雷及學習過程,希望能順便幫助一些,在學習或開發路上卡關的人們。

No responses yet