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.

当构建请求时,你讲经常性地和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 请求头中设置任何请求头类型。

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 选项。如果你不想在你的请求中发送任何请求体,那就选这个选项。如果你的请求确实有请求体,你可以选择一个合适的选项。默认的请求体选项如下:

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.

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为随后的请求保留你的文件路径。这同样可以帮助你运行那些含有需要文件上传的请求集合。

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.

这种编码方式和 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的数据,比如,图片,音频或者视频文件。你也可以发送文本文件。

转载于:https://my.oschina.net/u/3412738/blog/3060418

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Postman中,接口RequestBody是指在发送请求时,通过该参数来传递请求体的内容。在引用中的示例代码中,@RequestBody注解用于将请求体映射到StudentScore对象中。通过该注解,可以将请求体的JSON数据转化为Java对象。实际上,Postman支持发送多种格式的请求体数据,包括JSON、XML等。对于JSON格式的请求体数据,可以使用{}表示,而对于数组格式的请求体数据,则可以使用[]表示。在引用中提到了配置自增或时间戳随机参数、请求Cookies设置、以及不同注解的使用情况(@RequestParam、@PathVariable、@RequestBody等)。综上所述,Postman可以通过RequestBody参数来传递请求体的内容,以便进行接口测试和调试。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Postman测试@RequestBody和@RequestParam参数案例](https://blog.csdn.net/qq_44824164/article/details/130396215)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Postman使用详解(文档+视频+postman请求导出文件+后台java工程演示资源).rar](https://download.csdn.net/download/gongjin28_csdn/37714378)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值