Postman-Request Body類型

Request Body

While constructing requests, you'll work frequently with the request body editor. Postman lets you send almost any kind of HTTP request. The body editor is divided into five areas and has different controls, depending on the body type.web

當構建請求時,你講常常性地和request body編輯器打交道。Postman容許你發送幾乎全部的HTTP請求。body編輯器被分爲5部分,有不一樣的約束和限制,這取決於body的類型。服務器

Note about Headers: When you are sending requests through the HTTP protocol, your server might expect a Content-Type header. The Content-Type header allows the server to parse the body properly. For form-data and urlencoded body types, Postman automatically attaches the correct Content-Type header so you don't have to set it. The raw mode header is set when you select the formatting type. If you manually use a Content-Type header, that value takes precedence over what Postman sets. Postman does not set any header type for the binary body type.網絡

注意請求頭Headers: 當你經過HTTP協議發送請求時,你的服務器可能會期待着接收到一個 Content-Type (內容類型) 的請求頭。這個Content-Type請求頭將使服務器能夠恰當地解析請求頭。對於 form-data 和 urlencoded 的 body 請求體類型,Postman自動地附帶上正確的 Content-Type請求頭,因此你沒有必要去設置它。raw 模式的 請求體能夠在你選擇 格式化/排版 類型時選定。 若是你手動地設置一個 Content-Type 請求頭,你所設定的值將優先於Postman的設置。Postman不會再 binary 請求頭中設置任何請求頭類型。app

None

Postman defaults to 'none' option whenever you send a request. Choose this option if you don't want to send body with your request. If your request has a body, you may choose an appropriate option available there. The default body option appears as below:編輯器

無論你任什麼時候候發送一個請求,Postman默認都摸摸人使用 none 選項。若是你不想在你的請求中發送任何請求體,那就選這個選項。若是你的請求確實有請求體,你能夠選擇一個合適的選項。默認的請求體選項以下:ide

Form-data

form-data

multipart/form-data is the default encoding a web form uses to transfer data. This simulates filling a form on a website, and submitting it. The form-data editor lets you set key-value pairs (using the data editor for your data. It also lets you specify the content type for each part of a multi-part form request individually. You can attach files to a key as well. When you repeatedly make API calls that require sending these files again and again, Postman persists your file paths for subsequent use. This also helps you run collections that contain requests requiring file upload.post

Uploading multiple files each with their own Content-Type is not supported yet.網站

multipart/form-data是默認用來轉換網絡表單爲數據的請求體類型。它模擬了在一個網站上填寫一個表單,而後進行提交。form-data 編輯器容許你設置 鍵值對( key-value) (對你的數據使用 data editor)。它一樣容許你爲multi-part表單請求的每一部分都代表內容類型。你也能夠將一個文件加載到一個key上面。當你作那些須要一遍又一遍地發送這些文件的重複性API請求時,Postman爲隨後的請求保留你的文件路徑。這一樣能夠幫助你運行那些含有須要文件上傳的請求集合。ui

Urlencoded

urlencoded data

This encoding is the same as the one used in URL parameters. You just need to enter key-value pairs and Postman will encode the keys and values properly. Note that you cannot upload files through this encoding mode. There might be some confusion between form-data and urlencoded so make sure to check with your API first.this

這種編碼方式和 URL 參數方式是同樣的。你只須要輸入鍵值對,Postman就會將這些鍵值對恰當地編碼。注意,你不能經過這種編碼方式來上傳文件。在 form-data和urlencoded 這兩種方式之間可能有些混淆,因此必定要先檢查你的API。

Raw

raw data

A raw request can contain anything. Postman doesn’t touch the string entered in the raw editor except replacing environment variables. Whatever you put in the text area gets sent with the request. The raw editor lets you set the formatting type along with the correct header that you should send with the raw body. You can set the Content-Type header manually too and this will override the Postman defined setting. Selecting XML/JSON in the editor type enables syntax highlighting for your request body and also sets the Content-Type header.

raw(原始) 請求能夠包含任何類型的數據。Postman不會接觸 輸入到 raw 編輯器中的字符串,除非它取代環境變量。無論你在這個文本域中放入什麼,它都會被髮送到請求中。raw 編輯器容許你設置 帶有正確的 請求頭 的 排版類型,你應該使用 raw 請求體。你也能夠手動地設置 Content-Type 請求頭,而這將會改寫Postman的設置。在編輯類型中選擇XML/JSON可讓你的請求體 語法高亮,同時也能夠設置 Content-Type請求體。

Tip: Selecting text in the editor and pressing CMD/CTRL + B can beautify the XML/JSON content automatically.

Tip: 在編輯器中選擇文本,而後按 CMD/CTRL+B 可讓 XML/JSON內容自動地美化。

Binary

binary data

Binary data allows you to send things which you can not enter in Postman, for example, image, audio, or video files. You can send text files as well.

Binary (二進制) 數據容許你發送不能進入Postman的數據,好比,圖片,音頻或者視頻文件。你也能夠發送文本文件。

相關文章
相關標籤/搜索