如何在Postman中同时携带请求参数与请求体发送POST请求
How to Send Both @RequestParam and @RequestBody in Postman
Got it, let's break down why you're hitting those errors first, then fix it step by step:
- When you use
form-data, Postman sends data asmultipart/form-data. But your backend expects a separate request body (via@RequestBody)—form-data doesn't populate that dedicated body field, hence the "missing request body" error. - When you switch to
raw (Text), you're sending a request body, but you aren't including thetoandsubjectparameters that your@RequestParamannotations are looking for, so you get the "missing parameters" error.
Here's exactly how to set it up correctly:
Add your @RequestParam values in the Params tab
- Go to the Params tab (right next to the URL bar in Postman).
- Add two key-value pairs:
- Key:
to, Value: [your intended recipient, e.g.,user@example.com] - Key:
subject, Value: [your subject line, e.g.,Test Request]
Postman will automatically append these as query parameters to your request URL, which is exactly what@RequestParamexpects.
- Key:
Set up your @RequestBody in the Body tab
- Switch to the Body tab.
- Select the raw option, then use the dropdown menu to pick the right format (since your
@RequestBodyis aString,Textworks perfectly—if you were sending JSON, chooseJSONinstead). - In the text box below, paste or type your content string (e.g.,
This is the body content I want to send to the user).
Double-check the Content-Type header
- Postman usually sets this automatically when you select a raw format, but it's good to confirm:
- For
Textformat, theContent-Typeshould betext/plain. - For JSON format, it should be
application/json.
You can verify or adjust this in the Headers tab if needed.
- For
- Postman usually sets this automatically when you select a raw format, but it's good to confirm:
Hit send, and your backend should now receive both the to/subject parameters and the content body correctly.
内容的提问来源于stack exchange,提问作者Bartek
相关产品推荐
相关产品推荐

