如何在Postman中使用参数和正文进行发布请求 [英] How to make post request with params and body in Postman

查看:664
本文介绍了如何在Postman中使用参数和正文进行发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个端点,该端点需要很少的参数和主体作为输入,我想在Postman中对其进行测试。但是,当我在Postman后端的表单数据部分中输入数据时,会抛出我遗漏正文的错误。如果我尝试将数据输入到原始(文本)中,则会抱怨我忘记了参数。我该如何结合参数和身体?



编辑:


  1. 表单数据部分


  2. 原始部分


该端点的参数如下:

  @RequestParam( to)字符串至,
@RequestParam( subject)字符串主题,
@RequestBody字符串内容,
@RequestParam( isMultipart)布尔值isMultipart,
@RequestParam( isHtml)布尔值isHtml


解决方案

对于请求参数,您可以将其添加到 URL 的末尾,而不是添加到请求正文中,例如您已经在图片中完成了。
?to=random@email.com& subject =测试邮件功能& isMultipart = false&isHTML = true



当您选择 Params 按钮时,这可以在Postman UI中看到,可以在发送按钮。





我不确定您在请求正文中需要的字符串,端点需要此数据的格式。



如果采用JSON格式,则可以将 { content:一些新内容} 添加到原始正文,然后从下拉列表中选择 JSON(application / json),这还将设置正确的请求标头。 / p>

编辑:



自给出此答案以来,UI略有变化。 Params 标签现在放置在一个不太混乱的地方。




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?

EDIT:

  1. 'form-data' section

  2. 'raw' section

Parameters for that endpoint are following:

@RequestParam("to") String to,
@RequestParam("subject") String subject,
@RequestBody String content,
@RequestParam("isMultipart") Boolean isMultipart,
@RequestParam("isHtml") Boolean isHtml

解决方案

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. ?to=random@email.com&subject=Testing mailing feature&isMultipart=false&isHTML=true

This can be seen in the Postman UI when you select the Params button, this can be found next to the Send button.

I'm unsure about the string that you need in the request body and in what format the endpoint requires this data.

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.

Edit:

The UI has changed slightly since this answer was given. The Paramstab is now placed in a less confusing place.

这篇关于如何在Postman中使用参数和正文进行发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆