问题描述
我有一个端点,它需要很少的参数和正文作为输入,我想在 Postman 中测试它.但是,当我将数据输入到 Postman 后端的表单数据"部分时,会抛出我缺少正文的错误.如果我尝试将数据输入原始"(文本),它会抱怨我忘记了参数.如何结合参数和身体?
I have endpoint which takes few parameters and body as input, and I want to test it in Postman. But, when I input data into 'form-data' section in Postman backend throws error that I am missing body. If I try input data into 'raw' (Text) it complains that I forgot about parameters. How can I combine params and body?
'form-data' 部分
'form-data' section
原始"部分
该端点的参数如下:
@RequestParam("to") String to,
@RequestParam("subject") String subject,
@RequestBody String content,
@RequestParam("isMultipart") Boolean isMultipart,
@RequestParam("isHtml") Boolean isHtml
推荐答案
对于请求参数,您可以将它们添加到 URL
的末尾,而不是像您在请求正文中所做的那样图片.[email protected]&subject=测试邮件功能&isMultipart=false&isHTML=true
For the request params you would add them to the end of the URL
rather than in the request body, like you have done in the image.[email protected]&subject=Testing mailing feature&isMultipart=false&isHTML=true
这可以在您选择 Params
按钮时在 Postman UI 中看到,这可以在 Send
按钮旁边找到.
This can be seen in the Postman UI when you select the Params
button, this can be found next to the Send
button.
我不确定您在请求正文中需要的 string
以及端点需要此数据的格式.
I'm unsure about the string
that you need in the request body and in what format the endpoint requires this data.
如果它是 JSON 格式,您可以将 {"content": "Some new content"}
添加到 raw
正文并选择 JSON (application/json)
从下拉列表中,这也将设置正确的请求标头.
If it's in a JSON format you could add {"content": "Some new content"}
to the raw
body and select JSON (application/json)
from the dropdown, this will also set the correct request header.
自给出此答案以来,用户界面略有变化.Params
标签现在被放置在一个不那么容易混淆的地方.
The UI has changed slightly since this answer was given. The Params
tab is now placed in a less confusing place.
这篇关于如何在 Postman 中使用参数和正文进行发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!